jd-opensource/joyagent-jdgenie · error · Exception

file not found

Error message

file not found

What it means

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'.

Solutions

  1. Verify the request_id corresponds to a recently uploaded file in the same environment
  2. Re-upload the file to get a fresh file_id/request_id and retry
  3. Check the file store/service for the record and its retention/expiry policy

Example fix

// before
resp = requests.post(GET_FILE_URL, json={"request_id": old_id})
// after
if resp.status_code != 200:
    fresh = requests.post(UPLOAD_URL, files=...).json()
    resp = requests.post(GET_FILE_URL, json={"request_id": fresh["requestId"]})
Defensive patterns

Strategy: try-catch

Validate before calling

if not request_id or not file_name:
    raise ValueError("request_id and file_name are required")

Type guard

def has_file_ref(body) -> bool:
    return bool(getattr(body, "request_id", None)) and bool(getattr(body, "file_name", None))

Try / catch

try:
    resp = requests.post(GET_FILE_URL, json=payload)
    resp.raise_for_status()
except Exception:
    # 'file not found' -> re-upload and retry with a fresh id
    fresh = upload(...)
    resp = requests.post(GET_FILE_URL, json={"request_id": fresh["requestId"], ...})

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08). Data as JSON: /api/errors/c66ccc97da2930cb. Report an issue: GitHub.

Appendix: source

Thrown at genie-tool/genie_tool/api/file_manage.py:28

from genie_tool.db.file_table_op import FileInfoOp, get_file_preview_url, get_file_download_url


router = APIRouter(route_class=RequestHandlerRoute)


@router.post("/get_file")
async def get_file(
        body: FileRequest
):
    file_info = await FileInfoOp.get_by_file_id(file_id=body.file_id)
    if file_info:
        preview_url = get_file_preview_url(file_id=file_info.request_id, file_name=file_info.filename)
        download_url = get_file_download_url(file_id=file_info.request_id, file_name=file_info.filename)
        return JSONResponse(
            content={"ossUrl": download_url, "downloadUrl": download_url, "domainUrl": preview_url, "requestId": body.request_id,
                     "fileName": body.file_name})
    else:
        raise Exception("file not found")


@router.post("/upload_file")
async def upload_file(
        body: FileUploadRequest
):
    file_info = await FileInfoOp.add_by_content(
        filename=body.file_name, content=body.content, file_id=body.file_id, description=body.description,
        request_id=body.request_id)
    preview_url = get_file_preview_url(file_id=file_info.request_id, file_name=file_info.filename)
    download_url = get_file_download_url(file_id=file_info.request_id, file_name=file_info.filename)
    return JSONResponse(content={"ossUrl": download_url, "downloadUrl": download_url, "domainUrl": preview_url, "fileSize": file_info.file_size})

@router.post("/upload_file_data")
async def upload_file_data(file: UploadFile = File(...), request_id: str = Form(alias="requestId")):
    file.filename = unquote(file.filename)
    file_id = get_file_id(request_id, file.filename)
    file_info = await FileInfoOp.add_by_file(file=file, file_id=file_id, request_id=request_id)

View on GitHub (pinned to 2417e0b8b6)