{"record":{"id":"a3f2baa252db18a7","repo":"gastownhall/beads","slug":"get-labels-from-s-w","errorCode":null,"errorMessage":"get labels from %s: %w","messagePattern":"get labels from (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/issue_search.go","lineNumber":374,"sourceCode":"\t}\n\n\treturn nil\n}\n\n//nolint:gosec // G201: labelTable is \"labels\" or \"wisp_labels\" (hardcoded by callers).\nfunc (r *issueSQLRepositoryImpl) getLabelsFromTable(ctx context.Context, labelTable string, ids []string) (map[string][]string, error) {\n\tresult := make(map[string][]string)\n\tfor start := 0; start < len(ids); start += queryBatchSize {\n\t\tend := start + queryBatchSize\n\t\tif end > len(ids) {\n\t\t\tend = len(ids)\n\t\t}\n\t\tplaceholders, args := buildInPlaceholders(ids[start:end])\n\t\trows, err := r.runner.QueryContext(ctx, fmt.Sprintf(\n\t\t\t`SELECT issue_id, label FROM %s WHERE issue_id IN (%s) ORDER BY issue_id, label`,\n\t\t\tlabelTable, placeholders), args...)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"get labels from %s: %w\", labelTable, err)\n\t\t}\n\t\tfor rows.Next() {\n\t\t\tvar issueID, label string\n\t\t\tif err := rows.Scan(&issueID, &label); err != nil {\n\t\t\t\t_ = rows.Close()\n\t\t\t\treturn nil, fmt.Errorf(\"get labels: scan: %w\", err)\n\t\t\t}\n\t\t\tresult[issueID] = append(result[issueID], label)\n\t\t}\n\t\t_ = rows.Close()\n\t\tif err := rows.Err(); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"get labels: rows: %w\", err)\n\t\t}\n\t}\n\treturn result, nil\n}\n\n//nolint:gosec // G201: depTable is \"dependencies\" or \"wisp_dependencies\" (hardcoded by callers).","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/issue_search.go#L356-L392","documentation":"Raised when the batched label lookup in getLabelsFromTable fails to execute its query against the label table, wrapped as \"get labels from <table>: <err>\". IDs are chunked (queryBatchSize=200) with IN (...) placeholders, so errors come from the driver: missing table, lock, connection, or malformed placeholders/args.","triggerScenarios":"Search or fetchIssuesByIDs hydration issues that have labels; the SELECT ... WHERE issue_id IN (...) fails because the label table doesn't exist, the DB is locked, the connection drops, or the batch exceeds driver limits.","commonSituations":"Legacy databases without the labels table; schema renamed between bd versions; extremely large ID batches against drivers with IN-clause limits (SQLite variable caps); concurrent write locks.","solutions":["Unwrap to identify the driver error (no such table vs locked vs too many parameters).","Run `bd doctor` / migrations to create the label table with the expected schema.","If hitting a parameter limit, ensure you are on a current bd version that batches IDs (200 per batch).","Clear competing locks and retry; verify DB file permissions and disk space."],"exampleFix":"// before\n// old bd version builds one giant IN(...) -> \"too many SQL variables\"\n// after\nupgrade bd to a version batching label lookups (queryBatchSize = 200)\n// or repair schema: bd doctor && bd migrate","handlingStrategy":"validation","validationCode":"if err := bd.CheckTables(dbPath, \"labels\"); err != nil {\n\treturn fmt.Errorf(\"run `bd migrate`: %w\", err)\n}\nif len(issueIDs) == 0 { return nil } // skip empty label lookups","typeGuard":"func isLabelLookupError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"get labels from \")\n}","tryCatchPattern":"page, err := store.Search(ctx, q, filter)\nif err != nil && isLabelLookupError(err) {\n\tif strings.Contains(err.Error(), \"too many\") {\n\t\t// driver parameter cap hit; upgrade bd (batched lookups) or chunk IDs\n\t}\n\treturn fmt.Errorf(\"label lookup failed: %w\", err)\n}","preventionTips":["Keep bd up to date so label lookups are batched (200 IDs per query).","Run migrations when labels tables are introduced or renamed.","Avoid external tools inserting labels with NULL keys.","Verify driver parameter limits when embedding a custom SQL driver."],"tags":["database","sql","labels","batch-query"],"backgroundTag":"sql-query-execution-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}