{"record":{"id":"eecc390a1808e22d","repo":"tursodatabase/turso","slug":"error-querying-schema","errorCode":null,"errorMessage":"Error querying schema: {}","messagePattern":"Error querying schema: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/app.rs","lineNumber":1638,"sourceCode":"                ),\n                None => format!(\"SELECT name FROM {name}.sqlite_schema WHERE type='index' ORDER BY 1\"),\n            };\n            let handler = |row: &turso_core::Row| {\n                if let Ok(Value::Text(idx)) = row.get::<&Value>(0) {\n                    if let Some(prefix) = prefix {\n                        indexes.push_str(prefix);\n                        indexes.push('.');\n                    }\n                    indexes.push_str(idx.as_str());\n                    indexes.push(' ');\n                }\n                Ok(())\n            };\n            if let Err(err) = self.handle_row(&sql, handler) {\n                if err.to_string().contains(\"no such table: sqlite_schema\") {\n                    return Err(anyhow::anyhow!(\"Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized.\"));\n                } else {\n                    return Err(anyhow::anyhow!(\"Error querying schema: {}\", err));\n                }\n            }\n        }\n        if !indexes.is_empty() {\n            let _ = self.writeln(indexes.trim_end().as_bytes());\n        }\n        Ok(())\n    }\n\n    fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {\n        let mut tables = String::new();\n\n        for name in self.database_names()? {\n            let prefix = (name != \"main\").then_some(&name);\n            let sql = match pattern {\n                Some(pattern) => format!(\n                    \"SELECT name FROM {name}.sqlite_schema WHERE type in ('table', 'view') AND name NOT LIKE 'sqlite_%' AND name LIKE '{pattern}' ORDER BY 1\"\n                ),","sourceCodeStart":1620,"sourceCodeEnd":1656,"githubUrl":"https://github.com/tursodatabase/turso/blob/bad083fafbefdeae9a42ec19bdaaad8918dcf411/cli/app.rs#L1620-L1656","documentation":"The generic failure branch of '.indexes' (display_indexes in cli/app.rs): any error other than the specific missing-sqlite_schema case that occurs while selecting index names from the schema is wrapped with 'Error querying schema: {err}', with the underlying engine error appended verbatim.","triggerScenarios":"Running '.indexes [pattern]' where the backing query fails for a non-schema-table reason: I/O error reading the file, a malformed database image, an unattached 'db.' prefix used in the pattern, or an internal engine error surfacing through handle_row.","commonSituations":"Database file deleted or permissions changed while the CLI session was open; corrupted page containing the schema b-tree; scripts that assume an ATTACH that never happened.","solutions":["Read the appended inner error text — it names the real cause (I/O, malformed image, locked, ...).","Run PRAGMA integrity_check; to test the file.","Run '.databases' to confirm which databases are actually attached before using a 'db.' prefix.","If the inner error mentions locking, close competing writers or retry after they finish."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"-- Pre-flight the objects your pattern references:\n.databases               -- confirm the db prefix is attached\nSELECT name FROM sqlite_schema WHERE type='index' AND name LIKE 'my%';","typeGuard":null,"tryCatchPattern":"// Inspect the inner error: the wrapper only adds context, the cause is appended.\nif let Err(e) = shell.run_dot_command(\".indexes\") {\n    let msg = e.to_string();\n    let inner = msg.strip_prefix(\"Error querying schema: \").unwrap_or(&msg);\n    // branch on inner: io error vs malformed image vs unknown object\n}","preventionTips":["Surface the appended inner error first — it is the real diagnosis.","Run PRAGMA integrity_check on any file that starts throwing unexpected schema errors."],"tags":["cli","schema","indexes","query-error","io"],"backgroundTag":"sql-query-failed","analyzedSha":"bad083fafbefdeae9a42ec19bdaaad8918dcf411","analyzedAt":"2026-08-16T23:12:11.798Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}