HKUDS/DeepTutor · error · HTTPException

is empty.

Error message

{filename} is empty.

What it means

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.

Solutions

  1. Client: verify the selected file is non-empty before uploading
  2. Server: reject empty bodies earlier via Content-Length == 0 when available
  3. Client: fall back to a different export of the document if the first export produced a 0-byte file
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at deeptutor/api/routers/reading.py:202 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/7a7ccbcec82bebc6. Report an issue: GitHub.

Appendix: source

Thrown at deeptutor/api/routers/reading.py:202

    tmp_dir = Path(tempfile.mkdtemp(prefix="dt-reading-"))
    tmp_path = tmp_dir / Path(filename).name
    written = 0
    try:
        with tmp_path.open("wb") as sink:
            while chunk := await file.read(_UPLOAD_CHUNK):
                written += len(chunk)
                if written > MAX_MATERIAL_BYTES:
                    raise HTTPException(
                        status_code=413,
                        detail=(
                            f"{filename} exceeds the "
                            f"{MAX_MATERIAL_BYTES // (1024 * 1024)} MB limit."
                        ),
                    )
                sink.write(chunk)
        if written == 0:
            raise HTTPException(status_code=400, detail=f"{filename} is empty.")

        store = _store()
        manifest = store.ingest(tmp_path, filename=filename)
        return _detail(store, manifest)
    except HTTPException:
        raise
    except Exception as exc:
        raise _http_error(exc) from exc
    finally:
        shutil.rmtree(tmp_dir, ignore_errors=True)


@router.get("/materials/{material_id}", response_model=MaterialDetail)
async def get_material(material_id: str) -> MaterialDetail:
    store = _store()
    try:
        return _detail(store, store.manifest(material_id))
    except Exception as exc:

View on GitHub (pinned to 3e82f13042)