{"record":{"id":"2c3ced30aa8aa2c4","repo":"HKUDS/DeepTutor","slug":"link-not-found","errorCode":null,"errorMessage":"Link not found","messagePattern":"Link not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"deeptutor/api/routers/question_notebook.py","lineNumber":341,"sourceCode":"\n@router.post(\"/entries/{entry_id}/categories\")\nasync def add_entry_to_category(entry_id: int, payload: CategoryAddRequest):\n    store = get_sqlite_session_store()\n    entry = await store.get_notebook_entry(entry_id)\n    if entry is None:\n        raise HTTPException(status_code=404, detail=\"Entry not found\")\n    ok = await store.add_entry_to_category(entry_id, payload.category_id)\n    if not ok:\n        raise HTTPException(status_code=400, detail=\"Failed to add to category\")\n    return {\"added\": True, \"entry_id\": entry_id, \"category_id\": payload.category_id}\n\n\n@router.delete(\"/entries/{entry_id}/categories/{category_id}\")\nasync def remove_entry_from_category(entry_id: int, category_id: int):\n    store = get_sqlite_session_store()\n    removed = await store.remove_entry_from_category(entry_id, category_id)\n    if not removed:\n        raise HTTPException(status_code=404, detail=\"Link not found\")\n    return {\"removed\": True, \"entry_id\": entry_id, \"category_id\": category_id}\n\n\n# ── Overview ─────────────────────────────────────────────────────\n\n\n@router.get(\"/stats\", response_model=QuestionBankStats)\nasync def question_bank_stats() -> QuestionBankStats:\n    \"\"\"Counts behind the filter chips; also the agent's one-call overview.\"\"\"\n    store = get_sqlite_session_store()\n    return QuestionBankStats(**await store.question_bank_stats())\n\n\n# ── Category CRUD ────────────────────────────────────────────────\n\n\n@router.get(\"/categories\", response_model=list[CategoryItem])\nasync def list_categories():","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/api/routers/question_notebook.py#L323-L359","documentation":"Lookup guard: the entry-to-category link identified by the request could not be found in the store, so the referenced relation (not the entry or category itself) is the missing entity. Fires when deleting or updating a link that was already removed or never created.","triggerScenarios":"Thrown at deeptutor/api/routers/question_notebook.py:341 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Confirm the link exists with a GET before deleting or updating it","Treat 'link not found' on delete as idempotent success when retrying a cleanup","Check the entry_id and category_id are the same pair used when the link was created"],"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"}