{"record":{"id":"29a4527c9623820b","repo":"zeroclaw-labs/zeroclaw","slug":"failed-to-create-devices-table","errorCode":null,"errorMessage":"Failed to create devices table","messagePattern":"Failed to create devices table","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-gateway/src/api_pairing.rs","lineNumber":58,"sourceCode":"    pub fn new(workspace_dir: &Path) -> Self {\n        let db_path = workspace_dir.join(\"devices.db\");\n        let conn = Connection::open(&db_path).expect(\"Failed to open device registry database\");\n        conn.execute_batch(\n            \"PRAGMA journal_mode = WAL;\n             PRAGMA synchronous = NORMAL;\n             PRAGMA temp_store = MEMORY;\n             CREATE TABLE IF NOT EXISTS devices (\n                token_hash TEXT PRIMARY KEY,\n                id TEXT NOT NULL,\n                name TEXT,\n                device_type TEXT,\n                paired_at TEXT NOT NULL,\n                last_seen TEXT NOT NULL,\n                ip_address TEXT,\n                capabilities TEXT\n            )\",\n        )\n        .expect(\"Failed to create devices table\");\n\n        // Additive migration for DBs created before the capabilities column existed.\n        // SQLite has no IF NOT EXISTS for columns; the duplicate-column error here is benign.\n        let _ = conn.execute(\"ALTER TABLE devices ADD COLUMN capabilities TEXT\", []);\n\n        // Warm the in-memory cache from DB\n        let mut cache = HashMap::new();\n        let mut stmt = conn\n            .prepare(\"SELECT token_hash, id, name, device_type, paired_at, last_seen, ip_address, capabilities FROM devices\")\n            .expect(\"Failed to prepare device select\");\n        let rows = stmt\n            .query_map([], |row| {\n                let token_hash: String = row.get(0)?;\n                let id: String = row.get(1)?;\n                let name: Option<String> = row.get(2)?;\n                let device_type: Option<String> = row.get(3)?;\n                let paired_at_str: String = row.get(4)?;\n                let last_seen_str: String = row.get(5)?;","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-gateway/src/api_pairing.rs#L40-L76","documentation":"Panic-style fatal error in the pairing DeviceRegistry constructor: the SQL batch that opens WAL mode and creates the devices table failed. This happens during gateway startup when the devices.db file is corrupt, the schema DDL is rejected, or the SQLite file is not writable. Because pairing cannot function without the table, the registry treats this as an unrecoverable startup invariant and panics. Check workspace write permissions and remove/repair devices.db.","triggerScenarios":"Thrown at crates/zeroclaw-gateway/src/api_pairing.rs:58 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the device registry database is writable and not corrupted; restart the gateway to retry table creation.","Remove or restore a corrupted registry database file from backup and let it be recreated."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","contentChangedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}