[BUG]: Prevent Google Doc error message from being treated as quiz input#662
[BUG]: Prevent Google Doc error message from being treated as quiz input#662Ashvin-KS wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughIntroduces an Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
eduaid_web/src/pages/Text_Input.jsx
There was a problem hiding this comment.
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
inputErrorstate to display upload / Google Doc / validation errors separately fromtext. - 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.
|
Addressed the review feedback with a follow-up commit. What changed:
Validation:
|
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
eduaid_web/src/pages/Text_Input.jsx
| 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"); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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!
| const data = await apiClient.post("/get_content", { document_url: trimmedDocUrl }); | ||
| const docContent = typeof data === "string" ? data.trim() : ""; | ||
|
|
||
| if (docContent) { | ||
| submissionText = docContent; | ||
| setDocUrl(""); | ||
| setText(docContent); |
There was a problem hiding this comment.
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).
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:
inputErrorUI state on the Text Input pagetextstateAI Usage Disclosure:
Checklist
Validation:
Summary by CodeRabbit
New Features
Bug Fixes