{"record":{"id":"49c58a23f592a1fc","repo":"tursodatabase/turso","slug":"error-retrieving-columns-for-view","errorCode":null,"errorMessage":"Error retrieving columns for view '{}': {}","messagePattern":"Error retrieving columns for view '(.+?)': (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"cli/app.rs","lineNumber":1500,"sourceCode":"            false\n        }\n    }\n\n    /// Get column names for a view to generate the SQLite-compatible comment\n    fn get_view_columns(&mut self, view_name: &str) -> anyhow::Result<String> {\n        // Get column information using PRAGMA table_info\n        let pragma_sql = format!(\"PRAGMA table_info({view_name})\");\n\n        let mut columns = Vec::new();\n        let handler = |row: &turso_core::Row| {\n            // Column name is in the second column (index 1) of PRAGMA table_info\n            if let Ok(Value::Text(col_name)) = row.get::<&Value>(1) {\n                columns.push(col_name.as_str().to_string());\n            }\n            Ok(())\n        };\n        if let Err(err) = self.handle_row(&pragma_sql, handler) {\n            return Err(anyhow::anyhow!(\n                \"Error retrieving columns for view '{}': {}\",\n                view_name,\n                err\n            ));\n        }\n        if columns.is_empty() {\n            anyhow::bail!(\"PRAGMA table_info returned no columns for view '{}'. The view may be corrupted or the database schema is invalid.\", view_name);\n        }\n        Ok(columns.join(\",\"))\n    }\n\n    fn query_one_table_schema(\n        &mut self,\n        db_prefix: &str,\n        db_display_name: &str,\n        table_name: &str,\n    ) -> anyhow::Result<bool> {\n        // Yeah, sqlite also has this hardcoded: https://github.com/sqlite/sqlite/blob/31efe5a0f2f80a263457a1fc6524783c0c45769b/src/shell.c.in#L10765","sourceCodeStart":1482,"sourceCodeEnd":1518,"githubUrl":"https://github.com/tursodatabase/turso/blob/492c4a71cd7c2649e7df83da1471b74f4b1c7aa9/cli/app.rs#L1482-L1518","documentation":"Wrapper error from the CLI's view-column helper: it runs PRAGMA table_info(<view>) to collect column names (used for completion and schema listing) and any underlying failure is rethrown with the view name and original error (cli/app.rs:1490). A separate bail fires when the PRAGMA succeeds but returns zero columns.","triggerScenarios":"Tab-completing or listing columns of a view whose PRAGMA table_info fails: the view was dropped between schema read and PRAGMA execution, the view is malformed in sqlite_schema (corrupt schema), or the view name contains characters that break the unquoted interpolation into the PRAGMA.","commonSituations":"Another connection drops or recreates views while the shell is open; identifiers with spaces, hyphens, or keywords; schema corruption after a crash or partial write.","solutions":["Read the wrapped error text - it contains the exact PRAGMA failure reason","Confirm the view still exists: SELECT name FROM sqlite_schema WHERE type='view'","Refresh or reopen the connection so the schema cache is current, then retry","For identifiers with special characters, quote them in the PRAGMA (see fix)"],"exampleFix":"// before\nlet pragma_sql = format!(\"PRAGMA table_info({view_name})\");\n// after\nlet pragma_sql = format!(\"PRAGMA table_info('{}')\", view_name.replace('\\'', \"''\"));","handlingStrategy":"try-catch","validationCode":"let exists: bool = conn.query_row(\"SELECT COUNT(*) FROM sqlite_schema WHERE type='view' AND name=?\", [view])?;\nanyhow::ensure!(exists, \"view {view} not present\");","typeGuard":null,"tryCatchPattern":"match get_view_columns(app, &view) {\n    Ok(cols) => cols,\n    Err(e) if e.to_string().contains(\"Error retrieving columns\") => Vec::new(), // skip completion\n    Err(e) => return Err(e),\n}","preventionTips":["Quote view names when interpolating into PRAGMA table_info","Re-check the schema after another connection may have dropped views","Treat completion lookups as best-effort; missing views should not break the shell"],"tags":["cli","completion","pragma","table-info","view","rust"],"backgroundTag":"metadata-query-failed","analyzedSha":"492c4a71cd7c2649e7df83da1471b74f4b1c7aa9","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}