{"record":{"id":"e1b08323e16ee17b","repo":"lfnovo/open-notebook","slug":"notebook-not-found-e1b083","errorCode":null,"errorMessage":"Notebook not found","messagePattern":"Notebook not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"api/routers/insights.py","lineNumber":85,"sourceCode":"        insight = await SourceInsight.get(insight_id)\n        if not insight:\n            raise HTTPException(status_code=404, detail=\"Insight not found\")\n\n        # Use the existing save_as_note method from the domain model\n        note = await insight.save_as_note(request.notebook_id)\n\n        return NoteResponse(\n            id=note.id or \"\",\n            title=note.title,\n            content=note.content,\n            note_type=note.note_type,\n            created=str(note.created),\n            updated=str(note.updated),\n        )\n    except HTTPException:\n        raise\n    except NotFoundError:\n        raise HTTPException(status_code=404, detail=\"Notebook not found\")\n    except InvalidInputError as e:\n        raise HTTPException(status_code=400, detail=str(e))\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error saving insight {insight_id} as note: {str(e)}\")\n        raise HTTPException(\n            status_code=500, detail=\"Error saving insight as note\"\n        )\n","sourceCodeStart":67,"sourceCodeEnd":95,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/insights.py#L67-L95","documentation":"HTTP 404 raised in save_insight_as_note when the domain layer raises NotFoundError — meaning the notebook_id supplied in the request body doesn't reference an existing notebook.","triggerScenarios":"POST /api/insights/{id}/save-as-note with a notebook_id that was deleted, never existed, or belongs to another environment.","commonSituations":"Default notebook deleted; frontend sending a cached/stale notebook id; multi-environment configs where notebook ids differ.","solutions":["GET the notebooks list and use a current notebook_id","If the intended notebook was deleted, create it first or choose another","Ensure the client refreshes notebook ids after deletion events"],"exampleFix":"// before\n{\"notebook_id\": \"notebook:old456\"}\n// after\nnotebooks = await client.get(\"/api/notebooks\").json()\n{\"notebook_id\": notebooks[0][\"id\"]}","handlingStrategy":"validation","validationCode":"notebooks = (await client.get(\"/api/notebooks\")).json()\nif payload[\"notebook_id\"] not in {n[\"id\"] for n in notebooks}:\n    payload[\"notebook_id\"] = notebooks[0][\"id\"]  # or prompt","typeGuard":"def is_notebook_id(nid: str, notebooks: list[dict]) -> bool:\n    return nid in {n[\"id\"] for n in notebooks}","tryCatchPattern":"try:\n    await client.post(f\"/api/insights/{insight_id}/save-as-note\", json=payload)\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code == 404 and \"Notebook\" in e.response.text:\n        notebooks = (await client.get(\"/api/notebooks\")).json()\n        payload[\"notebook_id\"] = notebooks[0][\"id\"]\n        await client.post(f\"/api/insights/{insight_id}/save-as-note\", json=payload)\n    raise","preventionTips":["Fetch fresh notebook ids before save-as-note actions","Don't cache default notebook ids across sessions","When deleting a notebook, update clients/settings that reference it"],"tags":["http-404","not-found","notebook","insight","save-as-note"],"backgroundTag":"resource-not-found","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}