{"record":{"id":"c66ccc97da2930cb","repo":"jd-opensource/joyagent-jdgenie","slug":"file-not-found","errorCode":null,"errorMessage":"file not found","messagePattern":"file not found","errorType":"http","errorClass":"Exception","httpStatus":500,"severity":"error","filePath":"genie-tool/genie_tool/api/file_manage.py","lineNumber":28,"sourceCode":"from genie_tool.db.file_table_op import FileInfoOp, get_file_preview_url, get_file_download_url\n\n\nrouter = APIRouter(route_class=RequestHandlerRoute)\n\n\n@router.post(\"/get_file\")\nasync def get_file(\n        body: FileRequest\n):\n    file_info = await FileInfoOp.get_by_file_id(file_id=body.file_id)\n    if file_info:\n        preview_url = get_file_preview_url(file_id=file_info.request_id, file_name=file_info.filename)\n        download_url = get_file_download_url(file_id=file_info.request_id, file_name=file_info.filename)\n        return JSONResponse(\n            content={\"ossUrl\": download_url, \"downloadUrl\": download_url, \"domainUrl\": preview_url, \"requestId\": body.request_id,\n                     \"fileName\": body.file_name})\n    else:\n        raise Exception(\"file not found\")\n\n\n@router.post(\"/upload_file\")\nasync def upload_file(\n        body: FileUploadRequest\n):\n    file_info = await FileInfoOp.add_by_content(\n        filename=body.file_name, content=body.content, file_id=body.file_id, description=body.description,\n        request_id=body.request_id)\n    preview_url = get_file_preview_url(file_id=file_info.request_id, file_name=file_info.filename)\n    download_url = get_file_download_url(file_id=file_info.request_id, file_name=file_info.filename)\n    return JSONResponse(content={\"ossUrl\": download_url, \"downloadUrl\": download_url, \"domainUrl\": preview_url, \"fileSize\": file_info.file_size})\n\n@router.post(\"/upload_file_data\")\nasync def upload_file_data(file: UploadFile = File(...), request_id: str = Form(alias=\"requestId\")):\n    file.filename = unquote(file.filename)\n    file_id = get_file_id(request_id, file.filename)\n    file_info = await FileInfoOp.add_by_file(file=file, file_id=file_id, request_id=request_id)","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-tool/genie_tool/api/file_manage.py#L10-L46","documentation":"Raised by the file_manage API's `get_file` endpoint when the file metadata lookup succeeds structurally but the backend reports the file does not exist (the non-success branch). It surfaces to the API caller as a 500 with the plain message 'file not found'.","triggerScenarios":"POSTing to get_file with a `request_id`/file name that has no corresponding record in the file store — expired, deleted, or never-uploaded file.","commonSituations":"Client caches a file_id from a previous session; file retention window elapsed; wrong environment (dev file ID queried against prod); typo in request_id.","solutions":["Verify the request_id corresponds to a recently uploaded file in the same environment","Re-upload the file to get a fresh file_id/request_id and retry","Check the file store/service for the record and its retention/expiry policy"],"exampleFix":"// before\nresp = requests.post(GET_FILE_URL, json={\"request_id\": old_id})\n// after\nif resp.status_code != 200:\n    fresh = requests.post(UPLOAD_URL, files=...).json()\n    resp = requests.post(GET_FILE_URL, json={\"request_id\": fresh[\"requestId\"]})","handlingStrategy":"try-catch","validationCode":"if not request_id or not file_name:\n    raise ValueError(\"request_id and file_name are required\")","typeGuard":"def has_file_ref(body) -> bool:\n    return bool(getattr(body, \"request_id\", None)) and bool(getattr(body, \"file_name\", None))","tryCatchPattern":"try:\n    resp = requests.post(GET_FILE_URL, json=payload)\n    resp.raise_for_status()\nexcept Exception:\n    # 'file not found' -> re-upload and retry with a fresh id\n    fresh = upload(...)\n    resp = requests.post(GET_FILE_URL, json={\"request_id\": fresh[\"requestId\"], ...})","preventionTips":["Fetch file metadata with a fresh upload rather than caching file IDs across sessions","Track file retention windows and re-upload expired files","Confirm you are querying the same environment where the file was uploaded"],"tags":["file","not-found","api"],"backgroundTag":"file-not-found","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}