srbhr/Resume-Matcher · error · HTTPException

Empty file

Error message

Empty file

What it means

upload_resume rejects zero-byte uploads with HTTP 400 and the literal detail 'Empty file'. This catches files that pass the content-type check but contain no data, preventing the parser from being invoked on nothing.

Source

Thrown at apps/backend/app/routers/resumes.py:653

    Optionally parses to structured JSON if LLM is configured.
    """
    # Validate file type
    if file.content_type not in ALLOWED_TYPES:
        raise HTTPException(
            status_code=400,
            detail=f"Invalid file type: {file.content_type}. Allowed: PDF, DOC, DOCX",
        )

    # Read and validate size
    content = await file.read()
    if len(content) > MAX_FILE_SIZE:
        raise HTTPException(
            status_code=413,
            detail=f"File too large. Maximum size: {MAX_FILE_SIZE // (1024 * 1024)}MB",
        )

    if len(content) == 0:
        raise HTTPException(status_code=400, detail="Empty file")

    # Convert to markdown
    try:
        markdown_content = await parse_document(content, file.filename or "resume.pdf")
    except Exception as e:
        logger.error(f"Document parsing failed: {e}")
        raise HTTPException(
            status_code=422,
            detail="Failed to parse document. Please ensure it's a valid PDF or DOCX file.",
        )

    # Validate extracted text is not empty (image-based PDFs / scanned documents)
    if not markdown_content or not markdown_content.strip():
        raise HTTPException(
            status_code=422,
            detail=(
                "Could not extract text from the uploaded file. The document may be "
                "image-based or scanned. Please upload a text-based PDF/DOCX with "

View on GitHub (pinned to 116f9cc3b0)

Solutions

  1. Verify the file size locally (ls -l / Get-Item) and re-export/re-download a non-empty document
  2. Add client-side validation to reject 0-byte files before calling the API
  3. Check disk space / export tooling if files are consistently empty

Example fix

// before: client posts whatever the input holds, even empty
const body = new FormData(); body.append('file', fileInput.files[0]);
// after: guard before upload
if (file.size === 0) { alert('Selected file is empty'); return; }
Defensive patterns

Strategy: validation

Validate before calling

// client: reject empty selections before upload
if (!file || file.size === 0) {
  throw new Error('Selected file is empty');
}

Type guard

const isNonEmptyFile = (f: File | null | undefined): f is File =>
  f instanceof File && f.size > 0;

Try / catch

try {
  await api.postForm('/resumes/upload', form);
} catch (e) {
  if (e.response?.status === 400 && e.response?.data?.detail === 'Empty file') {
    showToast('That file is empty — pick a valid resume file');
  }
}

Prevention

When it happens

Trigger: POST /api/v1/resumes/upload where the multipart part has zero bytes: uploading an empty file created by a failed export, a truncated/broken download, or a client sending an empty file field programmatically.

Common situations: Browser drop-zone handling an empty placeholder file; a test script posting a dummy empty file; interrupted downloads saved as 0-byte PDFs.

Related errors


AI-assisted analysis of srbhr/Resume-Matcher@116f9cc3b0 (2026-08-28). Data as JSON: /api/errors/e57cb7bdda2e8b83. Report an issue: GitHub.