{"record":{"id":"634377e452fd860b","repo":"Zie619/n8n-workflows","slug":"analytics-error-str-e","errorCode":null,"errorMessage":"Analytics error: {str(e)}","messagePattern":"Analytics error: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/analytics_engine.py","lineNumber":366,"sourceCode":"\n\n@analytics_app.get(\"/analytics/overview\", response_model=AnalyticsResponse)\nasync def get_analytics_overview():\n    \"\"\"Get comprehensive analytics overview.\"\"\"\n    try:\n        analytics_data = analytics_engine.get_workflow_analytics()\n        trends = analytics_engine.get_trend_analysis()\n        insights = analytics_engine.get_usage_insights()\n\n        return AnalyticsResponse(\n            overview=analytics_data[\"overview\"],\n            trends=trends,\n            patterns=analytics_data[\"patterns\"],\n            recommendations=analytics_data[\"recommendations\"],\n            generated_at=analytics_data[\"generated_at\"],\n        )\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Analytics error: {str(e)}\")\n\n\n@analytics_app.get(\"/analytics/trends\")\nasync def get_trend_analysis(days: int = Query(30, ge=1, le=365)):\n    \"\"\"Get trend analysis for specified period.\"\"\"\n    try:\n        return analytics_engine.get_trend_analysis(days)\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Trend analysis error: {str(e)}\")\n\n\n@analytics_app.get(\"/analytics/insights\")\nasync def get_usage_insights():\n    \"\"\"Get usage insights and patterns.\"\"\"\n    try:\n        return analytics_engine.get_usage_insights()\n    except Exception as e:\n        raise HTTPException(status_code=500, detail=f\"Insights error: {str(e)}\")","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/src/analytics_engine.py#L348-L384","documentation":"A generic 500 from the analytics overview endpoint. The handler calls analytics_engine.get_workflow_analytics(), get_trend_analysis(), and get_usage_insights() and packages them into AnalyticsResponse; any exception in those three calls is wrapped as 'Analytics error: {str(e)}'. The analytics engine typically derives its data from a usage-events SQLite DB, so missing tables or empty data are the usual root causes.","triggerScenarios":"GET the analytics overview endpoint when the analytics database has never been initialized (no usage_events table), when timestamp parsing inside trend analysis hits NULL/invalid rows, or when the engine was constructed against a wrong db_path.","commonSituations":"Fresh install where analytics collection never started; DB file deleted or moved; mixed-era rows after a schema change; the engine reading a path relative to a different cwd.","solutions":["Inspect the str(e) in the response detail to identify which of the three engine calls failed.","Initialize/recreate the analytics database (run the engine's init/seed step) so required tables exist.","Confirm the analytics engine's db_path resolves from the server's actual working directory.","If data is simply empty, ensure some usage events were recorded before querying analytics."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"from pathlib import Path\n\ndef analytics_ready(db_path: str) -> bool:\n    import sqlite3\n    if not Path(db_path).exists():\n        return False\n    conn = sqlite3.connect(db_path)\n    try:\n        tables = {r[0] for r in conn.execute(\"SELECT name FROM sqlite_master WHERE type='table'\")}\n        return \"usage_events\" in tables  # adjust to engine's required table\n    finally:\n        conn.close()","typeGuard":null,"tryCatchPattern":"try:\n    overview = client.get(\"/analytics/\").json()\nexcept HTTPError as e:\n    if e.response.status_code == 500 and \"Analytics error\" in e.response.text:\n        overview = None  # dashboard degrades to 'no data yet' state\n    else:\n        raise","preventionTips":["Initialize analytics storage during deployment, not lazily on first request.","Smoke-test analytics endpoints in a post-deploy check so cold-start breakage is caught before users.","Render 'no data' UI states when analytics return errors rather than blank pages."],"tags":["http-500","analytics","sqlite","fastapi","initialization"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}