{"record":{"id":"a5e65162b9fe3f6b","repo":"unslothai/unsloth","slug":"empty-file-not-allowed","errorCode":null,"errorMessage":"Empty file not allowed","messagePattern":"Empty file not allowed","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"studio/backend/routes/data_recipe/seed.py","lineNumber":454,"sourceCode":"@router.post(\"/seed/upload-unstructured-file\")\nasync def upload_unstructured_file(\n    file: UploadFile = FastAPIFile(...), block_id: str = Form(...)\n) -> UnstructuredFileUploadResponse:\n    _validate_safe_id(block_id, \"block_id\")\n\n    original_filename = file.filename or \"upload\"\n    ext = Path(original_filename).suffix.lower()\n    if ext not in UNSTRUCTURED_ALLOWED_EXTS:\n        raise HTTPException(\n            400,\n            f\"Unsupported file type: {ext}. Allowed: {', '.join(sorted(UNSTRUCTURED_ALLOWED_EXTS))}\",\n        )\n\n    content = await file.read()\n    size_bytes = len(content)\n\n    if size_bytes == 0:\n        raise HTTPException(400, \"Empty file not allowed\")\n\n    if size_bytes > UNSTRUCTURED_RECIPE_UPLOAD_MAX_BYTES:\n        raise HTTPException(\n            413,\n            f\"File too large ({size_bytes} bytes). Maximum is {UNSTRUCTURED_RECIPE_UPLOAD_MAX_LABEL}.\",\n        )\n\n    block_dir = UNSTRUCTURED_UPLOAD_ROOT / block_id\n    ensure_dir(block_dir)\n    current_total = _get_block_total_size(block_dir)\n    if current_total + size_bytes > UNSTRUCTURED_RECIPE_UPLOAD_TOTAL_MAX_BYTES:\n        raise HTTPException(\n            413,\n            f\"Total upload limit ({UNSTRUCTURED_RECIPE_UPLOAD_TOTAL_MAX_LABEL}) exceeded\",\n        )\n\n    file_id = uuid4().hex\n    raw_path = block_dir / f\"{file_id}{ext}\"","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/routes/data_recipe/seed.py#L436-L472","documentation":"HTTP 400 raised by POST /seed/upload-unstructured-file when the uploaded file body is zero bytes (len(content) == 0 after await file.read()). Empty documents cannot be chunked or previewed, so they are rejected up front.","triggerScenarios":"Multipart upload where the file part has a filename but empty body — an empty file picked in a file dialog, a truncated stream, or a programmatically created 0-byte file.","commonSituations":"User creates a placeholder .txt that was never written to; frontend aborts the read but still submits; upstream download failed silently leaving a 0-byte file that gets forwarded.","solutions":["Check file.size > 0 in the picker/submit handler before uploading.","If the file should have content, re-download or re-save it and verify in a text editor.","Log the filename and size client-side to identify which selection was empty."],"exampleFix":"// before\nformData.append('file', selectedFile);\n\n// after\nif (selectedFile.size === 0) { alert('File is empty'); return; }\nformData.append('file', selectedFile);","handlingStrategy":"validation","validationCode":"if (file.size === 0) { reportError(`${file.name} is empty`); return; }\nupload(file);","typeGuard":"function isNonEmptyFile(f: File): boolean { return f.size > 0; }","tryCatchPattern":"On 400 'Empty file not allowed', skip the file and flag it in the UI; never re-send the same 0-byte body.","preventionTips":["Filter zero-size selections before building the form data.","Validate downloads actually produced bytes before forwarding them to upload."],"tags":["upload","validation","http-400","empty-file"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}