{"record":{"id":"5c02abf5f4a8dadc","repo":"lfnovo/open-notebook","slug":"error-saving-insight-as-note","errorCode":null,"errorMessage":"Error saving insight as note","messagePattern":"Error saving insight as note","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/insights.py","lineNumber":92,"sourceCode":"        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":74,"sourceCodeEnd":95,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/insights.py#L74-L95","documentation":"Catch-all 500 from save_insight_as_note for unexpected exceptions during insight.save_as_note(notebook_id) — after NotFoundError (404), InvalidInputError (400), and OpenNotebookError have been handled.","triggerScenarios":"DB failure while creating the note record, unexpected domain errors from save_as_note (e.g., serialization of insight content), or model construction errors on NoteResponse.","commonSituations":"SurrealDB outage/restart, schema drift on the notes table, edge-case insight content that fails note validation.","solutions":["Check the log 'Error saving insight <id> as note' for the traceback","Verify notebook_id is valid before retrying (avoids masked domain errors)","Confirm DB health and retry","If a specific insight always fails, inspect its fields for nulls/odd content"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# validate both refs first to rule out masked 404/400 paths\nassert (await client.get(f\"/api/insights/{insight_id}\")).status_code == 200\nassert payload[\"notebook_id\"] in {n[\"id\"] for n in (await client.get(\"/api/notebooks\")).json()}","typeGuard":null,"tryCatchPattern":"try:\n    return await client.post(f\"/api/insights/{insight_id}/save-as-note\", json=payload)\nexcept httpx.HTTPStatusError as e:\n    if e.response.status_code >= 500:\n        await asyncio.sleep(1)\n        return await client.post(f\"/api/insights/{insight_id}/save-as-note\", json=payload)\n    raise","preventionTips":["Validate insight and notebook references before calling","Check server logs for the underlying save_as_note traceback","Keep DB healthy; most 500s here are connectivity/schema issues"],"tags":["http-500","internal-error","insight","note","database"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}