Skip to content

Fix Google Doc error message being treated as quiz input#576

Closed
Adilkhan6465 wants to merge 2 commits intoAOSSIE-Org:mainfrom
Adilkhan6465:fix/google-doc-error-treated-as-input
Closed

Fix Google Doc error message being treated as quiz input#576
Adilkhan6465 wants to merge 2 commits intoAOSSIE-Org:mainfrom
Adilkhan6465:fix/google-doc-error-treated-as-input

Conversation

@Adilkhan6465
Copy link
Copy Markdown
Contributor

@Adilkhan6465 Adilkhan6465 commented Mar 15, 2026

Addressed Issues:

Fixes #575

Problem

When a user enters an invalid Google Doc URL, the API request fails and the error message "Error retrieving Google Doc content" is stored in the text state.

If the user clicks Next afterwards, this error message is treated as valid input and sent to the backend to generate a quiz.

Fix

  • Introduced a separate inputError state for handling errors.
  • Prevented error messages from being stored in the text state.
  • Displayed the error message below the textarea instead.

Result

  • Error messages are no longer treated as quiz input.
  • Prevents invalid backend requests.
  • Improves error handling and user experience.

Screen Recording

google-doc-bug-fix.mp4.mp4

Additional Notes:

AI Usage Disclosure:

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact. AI slop is strongly discouraged and may lead to banning and blocking. Do not spam our repos with AI slop.

Check one of the checkboxes below:

  • 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.

I have used the following AI models and tools: TODO

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.

Summary by CodeRabbit

  • Bug Fixes
    • Displays a clear error message when document content cannot be retrieved, so users see immediate feedback.
    • Automatically clears the error message once content is successfully loaded, keeping the interface tidy.
    • Improves user-facing notifications during document loading to reduce confusion and better indicate success or failure.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f37b74d-9c9e-462c-bd03-04ccce3ec251

📥 Commits

Reviewing files that changed from the base of the PR and between 610d08a and e8f12a2.

📒 Files selected for processing (1)
  • eduaid_web/src/pages/Text_Input.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • eduaid_web/src/pages/Text_Input.jsx

📝 Walkthrough

Walkthrough

The Text_Input component adds an inputError state and uses it to display Google Doc retrieval errors separately instead of storing error text in the main text state.

Changes

Cohort / File(s) Summary
Error State Management
eduaid_web/src/pages/Text_Input.jsx
Adds inputError via useState(""); sets/clears inputError based on Google Doc fetch success/failure; avoids writing error messages into text; renders a conditional error paragraph when inputError is non-empty.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibble bugs and hop along the code,
I tuck error words in their proper mode,
No more sending mistakes to the quiz,
I guard the input—hoppity-whiz! 🥕✨

🚥 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 accurately describes the main fix: preventing error messages from being treated as quiz input when retrieving Google Docs fails.
Linked Issues check ✅ Passed The implementation fully addresses all requirements from issue #575: introduces inputError state, prevents error storage in text state, displays errors below textarea, and blocks invalid backend requests.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the Google Doc error handling issue; no out-of-scope modifications 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
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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

🧹 Nitpick comments (2)
eduaid_web/src/pages/Text_Input.jsx (2)

179-179: Consider clearing error state when user types.

When the user starts typing new content after an error, the inputError message remains visible. Clearing it on input change would provide better UX feedback.

Proposed enhancement
-            onChange={(e) => setText(e.target.value)}
+            onChange={(e) => {
+              setText(e.target.value);
+              if (inputError) setInputError("");
+            }}

Similarly for the URL input at line 209:

-            onChange={(e) => setDocUrl(e.target.value)}
+            onChange={(e) => {
+              setDocUrl(e.target.value);
+              if (inputError) setInputError("");
+            }}
🤖 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` at line 179, The input change handlers
should also clear the error state so the error message disappears as the user
types; update the onChange for the text input (where setText is called) to also
call the state setter that clears inputError (e.g., setInputError('') or
setInputError(null)), and do the same for the URL input's onChange (where setUrl
is called) so both handlers reset the inputError state when invoked.

35-38: File upload errors still exhibit the same bug pattern.

The PR correctly fixes Google Doc error handling, but file upload errors (lines 35 and 38) still use setText() for error messages. This means if a file upload fails, "Error uploading file" will still be stored in text and could be sent as quiz input.

For consistency, consider applying the same fix here.

Proposed fix
       try {
         const data = await apiClient.postFormData("/upload", formData);
-        setText(data.content || data.error);
+        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");
       }
🤖 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 - 38, The catch block in
the file upload flow currently writes the literal error message into the main
text state by calling setText("Error uploading file") (inside the try/catch
where setText(data.content || data.error) is used); change this to avoid
polluting the quiz input: remove the setText call in the catch and instead set a
dedicated error state (e.g., setUploadError or setErrorMessage — create it if
missing) and/or keep text unchanged, while still logging the error with
console.error; update the catch to use the same error-handling pattern used for
Google Doc errors so only an error state is updated and text is not overwritten
on failures.
🤖 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 59-63: The try/catch currently sets a fallback error string into
the text state (setText(data || "Error in retrieving")) which mixes error
messages into content; update the logic around setText and setInputError so that
setText only receives actual content (e.g., setText(data ?? "")) and preserve
error signalling via setInputError when data is falsy or in the catch block;
locate and change the call to setText in the same block that uses setInputError
so the UI shows an empty/previous content instead of embedding the error string.

---

Nitpick comments:
In `@eduaid_web/src/pages/Text_Input.jsx`:
- Line 179: The input change handlers should also clear the error state so the
error message disappears as the user types; update the onChange for the text
input (where setText is called) to also call the state setter that clears
inputError (e.g., setInputError('') or setInputError(null)), and do the same for
the URL input's onChange (where setUrl is called) so both handlers reset the
inputError state when invoked.
- Around line 35-38: The catch block in the file upload flow currently writes
the literal error message into the main text state by calling setText("Error
uploading file") (inside the try/catch where setText(data.content || data.error)
is used); change this to avoid polluting the quiz input: remove the setText call
in the catch and instead set a dedicated error state (e.g., setUploadError or
setErrorMessage — create it if missing) and/or keep text unchanged, while still
logging the error with console.error; update the catch to use the same
error-handling pattern used for Google Doc errors so only an error state is
updated and text is not overwritten on failures.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 968e3958-e5ea-4dcd-9c54-236ab338b734

📥 Commits

Reviewing files that changed from the base of the PR and between fc3bf1a and 610d08a.

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

Comment thread eduaid_web/src/pages/Text_Input.jsx Outdated
@Adilkhan6465
Copy link
Copy Markdown
Contributor Author

Closing this PR as the changes have been consolidated into a single unified PR that includes:

  • Input validation improvements
  • Google Doc URL handling
  • Proper error state management

Please refer to PR #609 for the complete implementation.

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

1 participant