lfnovo/open-notebook · error · HTTPException

Error saving insight as note

Error message

Error saving insight as note

What it means

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.

Source

Thrown at api/routers/insights.py:92

        return NoteResponse(
            id=note.id or "",
            title=note.title,
            content=note.content,
            note_type=note.note_type,
            created=str(note.created),
            updated=str(note.updated),
        )
    except HTTPException:
        raise
    except NotFoundError:
        raise HTTPException(status_code=404, detail="Notebook not found")
    except InvalidInputError as e:
        raise HTTPException(status_code=400, detail=str(e))
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Error saving insight {insight_id} as note: {str(e)}")
        raise HTTPException(
            status_code=500, detail="Error saving insight as note"
        )

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check the log 'Error saving insight <id> as note' for the traceback
  2. Verify notebook_id is valid before retrying (avoids masked domain errors)
  3. Confirm DB health and retry
  4. If a specific insight always fails, inspect its fields for nulls/odd content
Defensive patterns

Strategy: retry

Validate before calling

# validate both refs first to rule out masked 404/400 paths
assert (await client.get(f"/api/insights/{insight_id}")).status_code == 200
assert payload["notebook_id"] in {n["id"] for n in (await client.get("/api/notebooks")).json()}

Try / catch

try:
    return await client.post(f"/api/insights/{insight_id}/save-as-note", json=payload)
except httpx.HTTPStatusError as e:
    if e.response.status_code >= 500:
        await asyncio.sleep(1)
        return await client.post(f"/api/insights/{insight_id}/save-as-note", json=payload)
    raise

Prevention

When it happens

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

Common situations: SurrealDB outage/restart, schema drift on the notes table, edge-case insight content that fails note validation.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/5c02abf5f4a8dadc. Report an issue: GitHub.