{"record":{"id":"0dbebdf988f84e10","repo":"lfnovo/open-notebook","slug":"error-building-context-str-e","errorCode":null,"errorMessage":"Error building context: {str(e)}","messagePattern":"Error building context: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/chat.py","lineNumber":416,"sourceCode":"            raise HTTPException(status_code=404, detail=\"Notebook not found\")\n\n        context_data, total_content = await build_notebook_context(\n            notebook, request.context_config\n        )\n\n        char_count = len(total_content)\n        estimated_tokens = token_count(total_content) if total_content else 0\n\n        return BuildContextResponse(\n            context=context_data, token_count=estimated_tokens, char_count=char_count\n        )\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error building context: {str(e)}\")\n        raise HTTPException(status_code=500, detail=f\"Error building context: {str(e)}\")\n","sourceCodeStart":398,"sourceCodeEnd":417,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/chat.py#L398-L417","documentation":"Generic 500 from POST /chat/context when build_notebook_context or downstream processing throws an unexpected exception. Cause logged as 'Error building context: ...'.","triggerScenarios":"Corrupt source/note content failing during context assembly, embedding provider failures when notes need vectors, or DB errors reading notebook entries.","commonSituations":"A source stuck in a failed processing state; provider credentials missing for embeddings; very large notebooks hitting memory/timeout limits.","solutions":["Check the API log for the exact exception during context build","Inspect the notebook's sources/notes for failed or malformed entries and remove/reprocess them","Verify provider credentials and that the worker is running","Try a context config with fewer sources to isolate the failing item"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"const sources = await fetchSources(notebookId);\nif (sources.some(s => s.processing_status === 'failed')) throw new Error('Fix failed sources first');","typeGuard":null,"tryCatchPattern":"catch (e) { if (e.status === 500) fallbackToSmallerContext(); else throw e; }","preventionTips":["Reprocess or remove failed sources before building context","Limit context config size on large notebooks"],"tags":["http-500","internal-error","context-building"],"backgroundTag":"unhandled-server-exception","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}