{"record":{"id":"0d30399a88d8cf59","repo":"nikivdev/code","slug":"create-table-failed","errorCode":null,"errorMessage":"create table failed: {:?}","messagePattern":"create table failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/jazz_state.rs","lineNumber":162,"sourceCode":"            project_name STRING,\n            config_path STRING NOT NULL,\n            task STRING NOT NULL,\n            command STRING NOT NULL,\n            user_input STRING NOT NULL,\n            success BOOL NOT NULL,\n            status I64,\n            duration_ms I64 NOT NULL,\n            timestamp_ms I64 NOT NULL,\n            flow_version STRING NOT NULL,\n            used_flox BOOL NOT NULL,\n            output STRING NOT NULL\n        )\n    \"#;\n\n    match db.execute(sql) {\n        Ok(_) => Ok(()),\n        Err(DatabaseError::TableExists(_)) => Ok(()),\n        Err(err) => Err(anyhow::anyhow!(\"create table failed: {:?}\", err)),\n    }\n}\n\nfn insert_task_run(db: &Database, record: &InvocationRecord) -> Result<()> {\n    let status = record\n        .status\n        .map(|value| value.to_string())\n        .unwrap_or_else(|| \"NULL\".to_string());\n    let duration_ms = record.duration_ms.min(i64::MAX as u128) as i64;\n    let timestamp_ms = record.timestamp_ms.min(i64::MAX as u128) as i64;\n    let project_name = record\n        .project_name\n        .as_ref()\n        .map(|value| format!(\"'{}'\", sql_escape(value)))\n        .unwrap_or_else(|| \"NULL\".to_string());\n    let output = truncate_output(&record.output, OUTPUT_LIMIT);\n\n    let sql = format!(","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/jazz_state.rs#L144-L180","documentation":"ensure_schema executes the CREATE TABLE DDL for invocation records and maps any error other than TableExists to this anyhow error with the debug-formatted DatabaseError. It is thrown when the jazz2 table cannot be created for reasons other than it already existing.","triggerScenarios":"record_task_run → with_db → ensure_schema where db.execute(sql) fails with a non-TableExists error: syntax issue after migration, permission denied, disk full, or database locked.","commonSituations":"Older jazz2 file with incompatible schema, read-only DB location, concurrent writers during DDL, disk quota exceeded.","solutions":["Check the debug DatabaseError in the message to identify the root cause (locked/disk-full/permission)","Ensure the jazz2 file's directory is writable and has free space","Close competing processes and retry, or run once alone to let the schema be created","If the schema is incompatible, migrate or recreate the database"],"exampleFix":"// before\nErr(err) => Err(anyhow::anyhow!(\"create table failed: {:?}\", err)),\n// after\nErr(err) => Err(anyhow::anyhow!(\"create table failed: {err:#}\")) // include full cause chain","handlingStrategy":"try-catch","validationCode":"// preflight: ensure db dir writable and space available\nlet dir = db_path.parent().unwrap_or(std::path::Path::new(\".\"));\nlet probe = dir.join(\".f-write-probe\");\nstd::fs::write(&probe, b\"\")?;\nstd::fs::remove_file(&probe)?;","typeGuard":null,"tryCatchPattern":"match with_db(|db| ensure_schema(db)) {\n    Err(e) if e.to_string().starts_with(\"create table failed\") => {\n        eprintln!(\"check jazz2 permissions/disk; cause: {e:#}\");\n    }\n    other => other?,\n}","preventionTips":["Create the schema once at startup, not per record","Keep a stable DDL string across versions","Ensure disk space and writability where jazz2 lives","Handle TableExists (already done) and lock errors separately with retries"],"tags":["database","schema","sqlite"],"backgroundTag":"schema-creation-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}