tursodatabase/turso · error

Error querying schema

Error message

Error querying schema: {}

What it means

Generic wrapper thrown while listing indexes: the query against sqlite_schema failed with something other than the recognized 'no such table: sqlite_schema' error, so the original error is chained into 'Error querying schema' (cli/app.rs:1651). The underlying cause is visible in the message.

Solutions

  1. Read the chained error text - it names the underlying LimboError
  2. Run SELECT name FROM sqlite_schema WHERE type='index' manually to reproduce
  3. Run PRAGMA integrity_check to rule out corruption
  4. Reopen the database file; if the error persists, capture it and report with the file's header info
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = app.list_indexes(None) {
    if !e.to_string().contains("Unable to access database schema") {
        return Err(e); // real I/O or corruption problem, not a legacy/empty db
    }
}

Prevention

When it happens

Trigger: .indexes (or a prefixed .indexes db.pattern) while the schema query fails for a non-schema-missing reason: corrupt header, I/O error reading page 1, interrupted statement, or an engine-level failure preparing the query.

Common situations: Database file truncated or corrupted mid-session; storage I/O errors on network mounts; engine regressions in preparing a simple SELECT from sqlite_schema.

Related errors


AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-08-20). Data as JSON: /api/errors/eecc390a1808e22d. Report an issue: GitHub.

Appendix: source

Thrown at cli/app.rs:1661

                ),
                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 492c4a71cd)