{"record":{"id":"e2da41fa629c0d4c","repo":"rqlite/rqlite","slug":"res-i-error","errorCode":null,"errorMessage":"${res[i].Error}","messagePattern":"\\$\\{res\\[i\\]\\.Error\\}","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db/db.go","lineNumber":1905,"sourceCode":"\t\t\"hard_heap_limit\",\n\t\t\"soft_heap_limit\",\n\t\t\"cache_size\",\n\t\t\"freelist_count\",\n\t}\n\tstmts := make([]*command.Statement, len(pragmas))\n\tfor i, p := range pragmas {\n\t\tstmts[i] = &command.Statement{\n\t\t\tSql: fmt.Sprintf(\"PRAGMA %s\", p),\n\t\t}\n\t}\n\treq := &command.Request{Statements: stmts}\n\tres, err := db.Query(req, false)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor i, p := range pragmas {\n\t\tif res[i].Error != \"\" {\n\t\t\treturn nil, errors.New(res[i].Error)\n\t\t}\n\t\tms[p] = res[i].Values[0].Parameters[0].GetI()\n\t}\n\treturn ms, nil\n}\n\n// qualifyRowColumns prefixes each column name in rows with its originating table name.\nfunc qualifyRowColumns(conn *sql.Conn, query string, rows *command.QueryRows) error {\n\tif len(rows.Columns) == 0 {\n\t\treturn nil\n\t}\n\n\tvar tableNames []string\n\terr := conn.Raw(func(driverConn any) error {\n\t\tsqliteConn := driverConn.(*sqlite3.SQLiteConn)\n\t\tstmt, err := sqliteConn.Prepare(query)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":1887,"sourceCodeEnd":1923,"githubUrl":"https://github.com/rqlite/rqlite/blob/7586a4d1bdbd9a5a80021664c5a863cd850adb60/db/db.go#L1887-L1923","documentation":"When collecting PRAGMA values into a map (db.go:1905), the code runs a batched query and checks each result for a per-row Error string; the first non-empty one is returned verbatim as a Go error. The message equals the SQLite error text stored in res[i].Error, so it is dynamic and points at the specific PRAGMA that failed.","triggerScenarios":"Calling the PRAGMA-collection helper (used for status/introspection like pragma journal_mode, page_size, etc.) when one of the PRAGMA statements in the batch fails — e.g. an unsupported PRAGMA name or a locked/failed database handle.","commonSituations":"Requesting a PRAGMA not supported by the linked SQLite build; calling during a transient database error; status endpoints surfacing a failed pragma after a restore or hot-backup operation.","solutions":["Inspect the returned message (it is res[i].Error) and correlate it with the pragma at index i in the request list.","Remove or correct the unsupported/misspelled PRAGMA in the request list.","If transient (e.g. locked db), retry once the database is idle; check for checkpoint/backup activity."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"for i, r := range res {\n  if r.GetError() != \"\" {\n    return fmt.Errorf(\"pragma %q failed: %s\", pragmas[i], r.GetError())\n  }\n}","typeGuard":"func pragmaResultsOK(res []*command.QueryRow, pragmas []string) error {\n  for i, r := range res {\n    if r.GetError() != \"\" { return fmt.Errorf(\"pragma %q: %s\", pragmas[i], r.GetError()) }\n  }\n  return nil\n}","tryCatchPattern":"ms, err := helperPragmas(req)\nif err != nil {\n  // message is the raw SQLite error from one pragma; identify which and fix or drop it\n}","preventionTips":["Only request PRAGMAs supported by the linked SQLite build.","Wrap per-row errors with the pragma name for actionable logs.","Retry only for transient failures such as lock contention."],"tags":["sqlite","pragma","error-wrapping","introspection"],"backgroundTag":"sqlite-error-propagation","analyzedSha":"7586a4d1bdbd9a5a80021664c5a863cd850adb60","analyzedAt":"2026-09-03T07:03:02.260Z","contentChangedAt":"2026-09-03T07:03:02.260Z","schemaVersion":2},"datasetVersion":"2026-09-10T12:17:11.382Z"}