{"record":{"id":"b6b6fd8d4eb09d34","repo":"tursodatabase/turso","slug":"error-querying-database","errorCode":null,"errorMessage":"Error querying database: {}","messagePattern":"Error querying database: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/app.rs","lineNumber":1729,"sourceCode":"        match self.conn.query(sql) {\n            Ok(Some(ref mut rows)) => {\n                let res = rows.run_with_row_callback(handler);\n                match res {\n                    Ok(_) => {}\n                    Err(LimboError::Busy) => {\n                        let _ = self.writeln(\"database is busy\");\n                    }\n                    Err(LimboError::Interrupt) => {\n                        let _ = self.writeln(LimboError::Interrupt.to_string());\n                    }\n                    Err(err) => return Err(anyhow!(err)),\n                }\n            }\n            Ok(None) => {\n                let _ = self.writeln(\"No results returned from the query.\");\n            }\n            Err(err) => {\n                return Err(anyhow::anyhow!(\"Error querying database: {}\", err));\n            }\n        }\n        Ok(())\n    }\n\n    fn display_databases(&mut self) -> anyhow::Result<()> {\n        let sql = \"PRAGMA database_list\";\n        let conn = self.conn.clone();\n        let mut databases = Vec::new();\n        self.handle_row(sql, |row| {\n            if let (\n                Ok(Value::Numeric(Numeric::Integer(seq))),\n                Ok(Value::Text(name)),\n                Ok(file_value),\n            ) = (\n                row.get::<&Value>(0),\n                row.get::<&Value>(1),\n                row.get::<&Value>(2),","sourceCodeStart":1711,"sourceCodeEnd":1747,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/app.rs#L1711-L1747","documentation":"This is the shared handle_row helper (cli/app.rs:1707) behind the CLI's dot commands (.tables, .indexes, .databases, schema helpers). When conn.query(sql) itself fails — the statement could not even be prepared or started — the error is wrapped as 'Error querying database: {err}'. Busy and Interrupt get dedicated handling; every other failure funnels here.","triggerScenarios":"Any dot command whose backing SQL fails to prepare: referencing 'db.table' where 'db' is not attached, a corrupted catalog page, I/O errors reading the file, or SQL syntax the engine rejects.","commonSituations":"Typos in dot-command arguments; sessions left open after the file was rotated or unmounted; databases corrupted by concurrent writers; engine/parser gaps hit by generated SQL.","solutions":["Read the inner error text — it is the engine's real diagnosis (no such table, I/O error, malformed image, ...).","Fix the referenced object names and confirm attachments with '.databases'.","Run PRAGMA integrity_check; to rule out corruption.","Reopen the database in a fresh session if the file was touched externally."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"-- Run the dot command's backing SQL directly first to get the raw engine error:\nSELECT name FROM sqlite_schema WHERE type='table';  -- what .tables runs","typeGuard":null,"tryCatchPattern":"// Branch on the inner engine error carried by the wrapper:\nif let Err(e) = shell.handle_dot_command(cmd) {\n    let msg = e.to_string();\n    if msg.contains(\"Error querying database\") {\n        let inner = msg.split(\": \").last().unwrap_or(&msg);\n        // handle: unknown object name / io error / malformed database\n    }\n}","preventionTips":["Validate object names and attachments ('.databases') before dot commands that take 'db.' prefixes.","Run suspicious SQL directly in the REPL — the raw engine error is more actionable than the wrapper."],"tags":["cli","query","prepare-error","dot-commands"],"backgroundTag":"sql-query-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}