fix: surface upload validation errors and remove ghost cards (#16)#402
Open
Padmajakachare1911 wants to merge 1 commit into
Open
Conversation
…aram20h#16) Return consistent 400 detail strings for extension, MIME, magic bytes, and size checks. Toast upload and ingest failures in the UI, auto-remove failed cards, and restrict the sidebar dropzone to PDF only with updated helper copy. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issue
Closes #16
📋 Summary
Uploading an unsupported file (wrong extension, fake PDF, oversized file)
previously failed silently — the backend rejected the file but the
frontend never surfaced the error, leaving a ghost card in the list with
no content. This PR closes both failure paths: synchronous validation
errors (wrong type/size) now show a sonner toast and prevent the card
from appearing; async ingest failures show a brief error card that
auto-removes after 4 seconds.
🛠️ Changes Made
backend/app/routes/documents.py.pdfwith400:"Unsupported file type '.docx'. Only PDF files are accepted."
application/pdfwith400that does not start with
%PDFwith400:"The uploaded file does not appear to be a valid PDF."
settings.MAX_UPLOAD_SIZE_MB(20 MB) with
400:"File too large (X MB). Maximum allowed size is 20 MB."
validate_uploadhelper no longer called for uploadsdetailstrings are user-facing and consistentbackend/tests/test_document_upload_validation.py(updated).docx→ correct unsupported-type messagefrontend/src/app/dashboard/page.tsxtoastedFailuresref (Set<number>) to track which faileddoc IDs have already triggered a toast (prevents repeat fires on
every poll interval)
status === "failed"docs,fires one
toast.error()via sonner withdoc.error_message(falls back to generic message if null)
setTimeoutfrontend/src/components/document/DocumentSidebar.tsx"failed"status renders distinct badge (AlertCircleicon, red)and shows
doc.error_messagetext below the filenameacceptupdated to{ "application/pdf": [".pdf"] }(was also accepting.docx,.txt,.md) to match the backend's PDF-only validationToast system
✅ Test Results
Backend
7/7 passed in
test_document_upload_validation.pyManual smoke tests
.txtrenamed to.docx→ upload.jpgrenamed totest.pdf→ uploadpending→ready🔒 Edge Cases Covered
.pdfbut wrong bytes400status = "failed"+error_messagepersisted bydocument_ingestion.py(pre-existing); surfaced via pollingtoastedFailuresref prevents duplicate toastserror_messageis null.pdf— mismatch eliminated📝 Notes
document_ingestion.pyalready persistedstatus = "failed"anderror_messagebefore this PR — no changes needed thereerror_messageDB column confirmed present — no migration requiredDocumentUpload.tsxis not in the active component tree; upload UXlives in
DocumentSidebar.tsx— all changes applied there insteadsettings.MAX_UPLOAD_SIZE_MB), not 50 MBas suggested in the issue plan — aligned to the app's actual limit
📦 Dependencies Added
None — uses sonner already present in the project.
🧪 How to Test Locally