{"record":{"id":"35521e16f46a1cc8","repo":"gastownhall/beads","slug":"iter-issues-query-w","errorCode":null,"errorMessage":"iter issues: query: %w","messagePattern":"iter issues: query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/dolt/iter_issues.go","lineNumber":64,"sourceCode":"\t}\n\twhereSQL := \"\"\n\tif len(whereClauses) > 0 {\n\t\twhereSQL = \"WHERE \" + strings.Join(whereClauses, \" AND \")\n\t}\n\tlimitSQL := \"\"\n\tif filter.Limit > 0 {\n\t\tlimitSQL = fmt.Sprintf(\" LIMIT %d\", filter.Limit)\n\t}\n\n\t//nolint:gosec // G201: whereSQL contains column comparisons with ?, limitSQL is a safe integer\n\tq := fmt.Sprintf(`SELECT %s FROM issues %s %s ORDER BY priority ASC, created_at DESC, id ASC%s`,\n\t\tissueops.IssueSelectColumns, sqlbuild.LeaseJoin(\"issues\"), whereSQL, limitSQL)\n\n\tvar issues []*types.Issue\n\ttxErr := s.withReadTx(ctx, func(tx *sql.Tx) error {\n\t\trows, err := tx.QueryContext(ctx, q, args...)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"iter issues: query: %w\", err)\n\t\t}\n\t\tdefer func() { _ = rows.Close() }()\n\t\tids := make([]string, 0)\n\t\tfor rows.Next() {\n\t\t\tiss, scanErr := issueops.ScanIssueFrom(rows)\n\t\t\tif scanErr != nil {\n\t\t\t\treturn fmt.Errorf(\"iter issues: scan: %w\", scanErr)\n\t\t\t}\n\t\t\tissues = append(issues, iss)\n\t\t\tids = append(ids, iss.ID)\n\t\t}\n\t\tif err := rows.Err(); err != nil {\n\t\t\treturn fmt.Errorf(\"iter issues: rows: %w\", err)\n\t\t}\n\t\t// A *sql.Tx is bound to one connection, so the cursor must be closed\n\t\t// before the label query can run on it (idempotent with the defer).\n\t\t_ = rows.Close()\n\t\tlabelMap, err := issueops.GetLabelsForIssuesFromTableInTx(ctx, tx, \"labels\", ids)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/iter_issues.go#L46-L82","documentation":"IterIssues failed when executing the constructed SELECT via tx.QueryContext inside a read transaction. The SQL was built but the database refused or could not run it. IterIssues materializes results eagerly, so this error aborts before any iterator is returned.","triggerScenarios":"Calling IterIssues when the issues table or lease-joined columns are missing/renamed, the database is unavailable or locked, or the SQL text produced from the query+filter is invalid.","commonSituations":"Opening a .beads directory with a mismatched/empty Dolt database; Dolt server not running or crashed; schema migration not applied; column mismatch after upgrade.","solutions":["Read the wrapped driver error for the concrete SQL failure (unknown column, no such table, connection refused)","Ensure the Dolt database/server is running and the .beads directory is intact","Run schema migrations / bd doctor to align the DB schema with the binary","Verify the custom query string is valid for the issues table"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check backend availability before iterating\nif err := requireDoltBackend(fileCfg); err != nil { return err }","typeGuard":null,"tryCatchPattern":"iter, err := store.IterIssues(ctx, query, filter)\nif err != nil && strings.Contains(err.Error(), \"query:\") {\n    // transient DB issue: retry with backoff\n    return retryWithBackoff(func() error { _, err = store.IterIssues(ctx, query, filter); return err })\n}","preventionTips":["Ensure the Dolt server is running before batch operations","Run bd doctor / migrations after upgrading beads","Set adequate context timeouts for large queries"],"tags":["storage","dolt","sql","query-execution"],"backgroundTag":"sql-query-execution-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}