Skip to content

[BUG]: Prevent Google Doc error message from being treated as quiz input#662

Open
Ashvin-KS wants to merge 2 commits into
AOSSIE-Org:mainfrom
Ashvin-KS:fix/text-input-google-doc-error-state
Open

[BUG]: Prevent Google Doc error message from being treated as quiz input#662
Ashvin-KS wants to merge 2 commits into
AOSSIE-Org:mainfrom
Ashvin-KS:fix/text-input-google-doc-error-state

Conversation

@Ashvin-KS
Copy link
Copy Markdown
Contributor

@Ashvin-KS Ashvin-KS commented Apr 12, 2026

Addressed Issues:
Fixes #575

Screenshots/Recordings:
Not attached from CLI environment.

Additional Notes:
This PR keeps Google Doc retrieval errors separate from quiz content and prevents accidental invalid generation requests.

Key Improvements:

  • Added a dedicated inputError UI state on the Text Input page
  • Prevented Google Doc retrieval failures from being written into text state
  • Added guard logic to block Next when both text and Google Doc URL are empty
  • Preserved existing behavior for valid text input and valid Google Doc content
  • Added inline error display and clear-on-edit behavior for better UX

AI Usage Disclosure:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.
  • AI models/tools used: GitHub Copilot (GPT-5.3-Codex)

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • I have read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Validation:

  • npm --prefix eduaid_web run build (successful)
  • Existing lint warnings in unrelated files are unchanged

Summary by CodeRabbit

  • New Features

    • Added error validation and messaging for document sources, shown inline beneath the URL input.
    • Errors clear automatically when the text area or URL input change.
  • Bug Fixes

    • Prevent empty submissions by trimming and validating text and URL before saving.
    • Use retrieved and trimmed content for saves; clear the URL input on successful fetch.
    • Surface upload/retrieval failures as input errors instead of inserting error text into the editor.

Copilot AI review requested due to automatic review settings April 12, 2026 12:58
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

Introduces an inputError state in Text_Input.jsx, trims and validates textarea and Google Doc URL inputs, fetches doc content via /get_content, prevents error messages from being stored in text, and displays errors inline beneath the Google Doc URL input. (50 words)

Changes

Cohort / File(s) Summary
Text input error handling & validation
eduaid_web/src/pages/Text_Input.jsx
Added inputError state; clear error on input change; trim and validate text and docUrl; call /get_content for doc URLs and use trimmed returned content; set inputError on retrieval/upload failures instead of writing errors into text; save/send trimmed submissionText to localStorage/backend.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibbled at the buggy text,

found the error, left it vexed.
Trimmed the crumbs and cleared the mess,
now inputs hum with gentle finesse.
Hop—no wrong words sent to stress.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main bug fix: preventing Google Doc error messages from being treated as quiz input, which aligns perfectly with the core changeset.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #575: introducing inputError state, preventing error messages from being stored in text state, displaying errors separately, clearing inputError on input changes, and blocking progression when both sources are empty.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #575 requirements: inputError state management, error handling for Google Doc retrieval, validation logic, and related UI updates. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 70-89: The Google Doc fetch branch (checking trimmedDocUrl)
returns early and blocks the normal submit flow (and blocks fallback to textarea
when doc fetch fails); modify the logic in the trimmedDocUrl branch so that it
does not return before the overall submission path: attempt the fetch and on
success setText(docContent) and setDocUrl(""), on fetch failure setInputError
but do NOT return — instead allow the handler (e.g., handleSubmit / onSubmit) to
continue and use existing textarea content as fallback; ensure setLoading is
still cleared in finally and avoid double-submitting by gating the rest of the
submit logic on a single code path after the fetch attempt. Use the existing
symbols trimmedDocUrl, apiClient.post("/get_content"), setText, setDocUrl,
setInputError, setLoading and the component's submit handler name to locate and
update the code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 841ab3ef-6c59-457d-8c9c-3be8aedd530a

📥 Commits

Reviewing files that changed from the base of the PR and between 2038116 and bd92912.

📒 Files selected for processing (1)
  • eduaid_web/src/pages/Text_Input.jsx

Comment thread eduaid_web/src/pages/Text_Input.jsx
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the Text Input flow so Google Doc retrieval failures are shown as UI errors instead of being written into the quiz input text, preventing accidental invalid quiz-generation requests (Fixes #575).

Changes:

  • Introduced a dedicated inputError state to display upload / Google Doc / validation errors separately from text.
  • Updated Google Doc retrieval and file upload handling to avoid writing error strings into text.
  • Added input guards (trim + empty-check) and clear-on-edit behavior to improve UX and prevent “Next” from running with no real input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Ashvin-KS
Copy link
Copy Markdown
Contributor Author

Addressed the review feedback with a follow-up commit.

What changed:

  • Removed the Google Doc short-circuit that prevented quiz generation after successful doc fetch.
  • Converted submission flow to single-pass behavior.
  • Added fallback behavior: if Google Doc retrieval fails but textarea text is valid, submission now proceeds with typed text.
  • Kept error behavior unchanged when neither source is valid.

Validation:

  • npm --prefix eduaid_web run build (successful)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Around line 35-43: The component currently reuses the single state inputError
(setInputError) for both Google Doc URL validation and file-upload/page-level
errors, which causes upload errors to be shown under the Google Doc URL field;
add a separate error state (e.g., uploadError or pageError) and use it for file
upload and page-level validation paths (where setInputError is currently called
in the upload catch and the page validation branch), while keeping inputError
specific to the Google Doc URL validation; update the render logic in the
Text_Input component so the Google Doc field only displays inputError and a new
page-level slot displays uploadError/pageError accordingly (adjust places that
call setInputError to call the new setter where appropriate).
- Around line 74-80: The code currently treats any non-empty string returned
from apiClient.post("/get_content") as valid content, which lets the known error
sentinel "Error retrieving Google Doc content" get accepted; update the success
check around docContent (the value assigned from data) to reject that sentinel
(and ideally any string starting with "Error") before setting submissionText and
calling setDocUrl("")/setText(docContent); specifically, in the block that reads
const docContent = typeof data === "string" ? data.trim() : ""; add a guard like
if (docContent && docContent !== "Error retrieving Google Doc content" &&
!docContent.startsWith("Error")) { submissionText = docContent; setDocUrl("");
setText(docContent); } else handle the error path (do not assign or call
setText).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a5b08a4-9c71-4515-8c57-a85895a6892c

📥 Commits

Reviewing files that changed from the base of the PR and between bd92912 and d2fa941.

📒 Files selected for processing (1)
  • eduaid_web/src/pages/Text_Input.jsx

Comment on lines +35 to +43
if (data.content) {
setText(data.content);
setInputError("");
} else {
setInputError(data.error || "Error uploading file");
}
} catch (error) {
console.error("Error uploading file:", error);
setText("Error uploading file");
setInputError("Error uploading file");
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Render shared validation errors somewhere other than the Google Doc field.

Lines 35-43 and 63-67 now use inputError for upload failures and page-level validation, but Line 241 always renders that state under the Google Doc URL. After those paths, the UI points users at the wrong control. Either split the state by source or render non-doc errors in a page-level slot.

Also applies to: 63-67, 241-243

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Text_Input.jsx` around lines 35 - 43, The component
currently reuses the single state inputError (setInputError) for both Google Doc
URL validation and file-upload/page-level errors, which causes upload errors to
be shown under the Google Doc URL field; add a separate error state (e.g.,
uploadError or pageError) and use it for file upload and page-level validation
paths (where setInputError is currently called in the upload catch and the page
validation branch), while keeping inputError specific to the Google Doc URL
validation; update the render logic in the Text_Input component so the Google
Doc field only displays inputError and a new page-level slot displays
uploadError/pageError accordingly (adjust places that call setInputError to call
the new setter where appropriate).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ashvin-KS pleasse have a look into this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Comment on lines +74 to +80
const data = await apiClient.post("/get_content", { document_url: trimmedDocUrl });
const docContent = typeof data === "string" ? data.trim() : "";

if (docContent) {
submissionText = docContent;
setDocUrl("");
setText(docContent);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

The /get_content success check still accepts the known error sentinel as content.

In backend/server.py, Lines 246-255 still forward whatever string docs_service.get_document_content() returns. With the current truthy check, Line 77 will accept the exact sentinel from #575 ("Error retrieving Google Doc content") as valid docContent, so it can still be copied into text/submissionText and sent downstream.

💡 Minimal guard for the current API shape
         const data = await apiClient.post("/get_content", { document_url: trimmedDocUrl });
-        const docContent = typeof data === "string" ? data.trim() : "";
+        const rawDocContent = typeof data === "string" ? data.trim() : "";
+        const docContent =
+          rawDocContent && rawDocContent !== "Error retrieving Google Doc content"
+            ? rawDocContent
+            : "";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@eduaid_web/src/pages/Text_Input.jsx` around lines 74 - 80, The code currently
treats any non-empty string returned from apiClient.post("/get_content") as
valid content, which lets the known error sentinel "Error retrieving Google Doc
content" get accepted; update the success check around docContent (the value
assigned from data) to reject that sentinel (and ideally any string starting
with "Error") before setting submissionText and calling
setDocUrl("")/setText(docContent); specifically, in the block that reads const
docContent = typeof data === "string" ? data.trim() : ""; add a guard like if
(docContent && docContent !== "Error retrieving Google Doc content" &&
!docContent.startsWith("Error")) { submissionText = docContent; setDocUrl("");
setText(docContent); } else handle the error path (do not assign or call
setText).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Google Doc error message is treated as quiz input on Text_Input page

3 participants