{"record":{"id":"3395d84d8f4936c8","repo":"gastownhall/beads","slug":"db-get-s-w","errorCode":null,"errorMessage":"db: Get %s: %w","messagePattern":"db: Get (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/issue.go","lineNumber":564,"sourceCode":"\t\tStartedAtWasZero: startedWasZero,\n\t\tOldIssue:         oldIssue,\n\t}, nil\n}\n\nfunc (r *issueSQLRepositoryImpl) Get(ctx context.Context, id string, opts domain.IssueTableOpts) (*types.Issue, error) {\n\tif id == \"\" {\n\t\treturn nil, errors.New(\"db: Get: id must not be empty\")\n\t}\n\ttable := pickIssueTable(opts.UseWispsTable)\n\t//nolint:gosec // G201: table is one of two hardcoded constants\n\trow := r.runner.QueryRowContext(ctx, fmt.Sprintf(\"SELECT %s FROM %s %s WHERE id = ?\",\n\t\tissueSelectColumns, table, sqlbuild.LeaseJoin(table)), id)\n\tissue, err := scanIssue(row)\n\tif errors.Is(err, sql.ErrNoRows) {\n\t\treturn nil, sql.ErrNoRows\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"db: Get %s: %w\", id, err)\n\t}\n\treturn issue, nil\n}\n\nfunc (r *issueSQLRepositoryImpl) GetByIDs(ctx context.Context, ids []string, opts domain.IssueTableOpts) ([]*types.Issue, error) {\n\tif len(ids) == 0 {\n\t\treturn nil, nil\n\t}\n\tplaceholders := make([]string, len(ids))\n\targs := make([]any, len(ids))\n\tfor i, id := range ids {\n\t\tplaceholders[i] = \"?\"\n\t\targs[i] = id\n\t}\n\ttable := pickIssueTable(opts.UseWispsTable)\n\t//nolint:gosec // G201: table is one of two hardcoded constants\n\tq := fmt.Sprintf(\"SELECT %s FROM %s %s WHERE id IN (%s)\",\n\t\tissueSelectColumns, table, sqlbuild.LeaseJoin(table), strings.Join(placeholders, \",\"))","sourceCodeStart":546,"sourceCodeEnd":582,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/issue.go#L546-L582","documentation":"This error wraps any unexpected failure from the repository's Get path, adding the issue ID that was being fetched. It is thrown after scanIssue fails with an error other than sql.ErrNoRows (not-found is returned verbatim as sql.ErrNoRows, not wrapped). Callers like Update and Claim rely on Get to load the row before mutating it, so a wrapped driver/scan failure aborts the whole operation.","triggerScenarios":"Calling Get, Update, or Claim on issues via IssueSQLRepository when the underlying SELECT (with lease join) fails: driver-level query errors, connection drops, scan/type-mismatch errors, or corrupted rows. Not raised for missing IDs — those surface as sql.ErrNoRows.","commonSituations":"Database connection dropped mid-operation, schema drift after an upgrade (columns renamed/moved so scanIssue fails), permission changes revoking SELECT on issues, or context cancellation surfacing as a driver error.","solutions":["Read the wrapped cause (%w chain) to identify the driver error; fix the underlying DB problem (connection, schema, permissions).","Verify the DB schema matches the issueSelectColumns the code expects; run any provided migration/doctor command.","Check connectivity to the Dolt server and retry transient failures (network blips, context timeouts).","If scanning fails consistently for one issue, inspect that row for data that violates expected column types."],"exampleFix":"// before\nissue, err := repo.Get(ctx, id)\nif err != nil { return err } // loses ErrNoRows distinction\n// after\nissue, err := repo.Get(ctx, id)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) { return storage.ErrNotFound }\n    return fmt.Errorf(\"get issue %s: %w\", id, err)\n}","handlingStrategy":"try-catch","validationCode":"// verify connectivity before calling\nif err := sqlDB.PingContext(ctx); err != nil { return fmt.Errorf(\"db unavailable: %w\", err) }","typeGuard":null,"tryCatchPattern":"issue, err := repo.Get(ctx, id)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) { return storage.ErrNotFound }\n    var transient = isTransientDBErr(err) // inspect wrapped cause\n    if transient { return retry(...) }\n    return fmt.Errorf(\"get issue %s: %w\", id, err)\n}","preventionTips":["Always distinguish sql.ErrNoRows from wrapped failures via errors.Is.","Keep DB schema in sync with the library version before upgrading.","Ping the DB / use health checks before long-running operations.","Log the full error chain (%w causes) for diagnosis."],"tags":["database","storage","wrap"],"backgroundTag":"db-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}