{"record":{"id":"7a7ccbcec82bebc6","repo":"HKUDS/DeepTutor","slug":"filename-is-empty","errorCode":null,"errorMessage":"{filename} is empty.","messagePattern":"(.+?) is empty\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"deeptutor/api/routers/reading.py","lineNumber":202,"sourceCode":"\n    tmp_dir = Path(tempfile.mkdtemp(prefix=\"dt-reading-\"))\n    tmp_path = tmp_dir / Path(filename).name\n    written = 0\n    try:\n        with tmp_path.open(\"wb\") as sink:\n            while chunk := await file.read(_UPLOAD_CHUNK):\n                written += len(chunk)\n                if written > MAX_MATERIAL_BYTES:\n                    raise HTTPException(\n                        status_code=413,\n                        detail=(\n                            f\"{filename} exceeds the \"\n                            f\"{MAX_MATERIAL_BYTES // (1024 * 1024)} MB limit.\"\n                        ),\n                    )\n                sink.write(chunk)\n        if written == 0:\n            raise HTTPException(status_code=400, detail=f\"{filename} is empty.\")\n\n        store = _store()\n        manifest = store.ingest(tmp_path, filename=filename)\n        return _detail(store, manifest)\n    except HTTPException:\n        raise\n    except Exception as exc:\n        raise _http_error(exc) from exc\n    finally:\n        shutil.rmtree(tmp_dir, ignore_errors=True)\n\n\n@router.get(\"/materials/{material_id}\", response_model=MaterialDetail)\nasync def get_material(material_id: str) -> MaterialDetail:\n    store = _store()\n    try:\n        return _detail(store, store.manifest(material_id))\n    except Exception as exc:","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/reading.py#L184-L220","documentation":"Post-stream guard in POST /materials: the upload completed with zero bytes written, meaning the client sent an empty file body. An empty file cannot be ingested or rendered, so it is rejected after the copy loop.","triggerScenarios":"Thrown at deeptutor/api/routers/reading.py:202 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Client: verify the selected file is non-empty before uploading","Server: reject empty bodies earlier via Content-Length == 0 when available","Client: fall back to a different export of the document if the first export produced a 0-byte file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","contentChangedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}