tursodatabase/turso · error
Error querying schema: {}
Error message
Error querying schema: {} What it means
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.
Source
Thrown at cli/app.rs:1638
),
None => format!("SELECT name FROM {name}.sqlite_schema WHERE type='index' ORDER BY 1"),
};
let handler = |row: &turso_core::Row| {
if let Ok(Value::Text(idx)) = row.get::<&Value>(0) {
if let Some(prefix) = prefix {
indexes.push_str(prefix);
indexes.push('.');
}
indexes.push_str(idx.as_str());
indexes.push(' ');
}
Ok(())
};
if let Err(err) = self.handle_row(&sql, handler) {
if err.to_string().contains("no such table: sqlite_schema") {
return Err(anyhow::anyhow!("Unable to access database schema. The database may be using an older SQLite version or may not be properly initialized."));
} else {
return Err(anyhow::anyhow!("Error querying schema: {}", err));
}
}
}
if !indexes.is_empty() {
let _ = self.writeln(indexes.trim_end().as_bytes());
}
Ok(())
}
fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {
let mut tables = String::new();
for name in self.database_names()? {
let prefix = (name != "main").then_some(&name);
let sql = match pattern {
Some(pattern) => format!(
"SELECT name FROM {name}.sqlite_schema WHERE type in ('table', 'view') AND name NOT LIKE 'sqlite_%' AND name LIKE '{pattern}' ORDER BY 1"
),View on GitHub (pinned to bad083fafb)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
-- Pre-flight the objects your pattern references: .databases -- confirm the db prefix is attached SELECT name FROM sqlite_schema WHERE type='index' AND name LIKE 'my%';
Try / catch
// Inspect the inner error: the wrapper only adds context, the cause is appended.
if let Err(e) = shell.run_dot_command(".indexes") {
let msg = e.to_string();
let inner = msg.strip_prefix("Error querying schema: ").unwrap_or(&msg);
// branch on inner: io error vs malformed image vs unknown object
} Prevention
- Surface the appended inner error first — it is the real diagnosis.
- Run PRAGMA integrity_check on any file that starts throwing unexpected schema errors.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to access database schema. The database may be using
- Error retrieving columns for view '{}': {}
- PRAGMA table_info returned no columns for view '{}'. The vie
- Error in database list: {}
- getAllRows: exceeded ${MAX_IO_RETRIES} IO retries
AI-assisted analysis of tursodatabase/turso@bad083fafb (2026-08-16).
Data as JSON: /api/errors/eecc390a1808e22d.
Report an issue: GitHub.