{"record":{"id":"be7f7825f9acc643","repo":"HKUDS/DeepTutor","slug":"str-exc-be7f78","errorCode":null,"errorMessage":"str(exc)","messagePattern":"str\\(exc\\)","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"error","filePath":"deeptutor/api/routers/knowledge.py","lineNumber":2454,"sourceCode":"        )\n\n    dest_dir.mkdir(parents=True, exist_ok=True)\n    shutil.move(str(src), str(dest))\n    return {\"status\": \"ok\", \"path\": dest.relative_to(raw_dir.resolve()).as_posix()}\n\n\n@router.get(\"/{kb_name}/file-preview-text/{filename:path}\")\nasync def serve_kb_raw_file_text_preview(kb_name: str, filename: str):\n    \"\"\"Serve extracted plain text for a raw KB document preview.\"\"\"\n    target = _resolve_kb_raw_file_or_404(kb_name, filename)\n    try:\n        text = extract_text_from_path(\n            target,\n            max_bytes=DocumentValidator.MAX_FILE_SIZE,\n            max_chars=MAX_EXTRACTED_CHARS_PER_DOC,\n        )\n    except DocumentExtractionError as exc:\n        raise HTTPException(status_code=422, detail=str(exc)) from exc\n    except OSError as exc:\n        raise HTTPException(status_code=404, detail=\"File not found\") from exc\n\n    return PlainTextResponse(text, media_type=\"text/plain; charset=utf-8\")\n\n\n@router.get(\"/{kb_name}/files/{filename:path}\")\nasync def serve_kb_raw_file(kb_name: str, filename: str):\n    \"\"\"Serve a single raw document for inline preview / download.\n\n    Resolution is sandboxed to the KB's raw/ directory; any path that\n    escapes via traversal yields 403.\n    \"\"\"\n    target = _resolve_kb_raw_file_or_404(kb_name, filename)\n    media_type, _ = mimetypes.guess_type(target.name)\n    return FileResponse(\n        target,\n        media_type=media_type or \"application/octet-stream\",","sourceCodeStart":2436,"sourceCodeEnd":2472,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/knowledge.py#L2436-L2472","documentation":"Error \"str(exc)\" thrown in HKUDS/DeepTutor.","triggerScenarios":"Thrown at deeptutor/api/routers/knowledge.py:2454 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}