{"record":{"id":"b06948c67cf8f7bd","repo":"gastownhall/beads","slug":"db-labelsqlrepository-insert-s-s-verify-issue","errorCode":null,"errorMessage":"db: LabelSQLRepository.Insert %s/%s: verify issue: %w","messagePattern":"db: LabelSQLRepository\\.Insert (.+?)/(.+?): verify issue: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/label.go","lineNumber":70,"sourceCode":"\t\tfmt.Sprintf(\"INSERT IGNORE INTO %s (issue_id, label) VALUES (?, ?)\", table),\n\t\tissueID, label,\n\t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"db: LabelSQLRepository.Insert %s/%s: %w\", issueID, label, err)\n\t}\n\trows, err := result.RowsAffected()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"db: LabelSQLRepository.Insert %s/%s: rows affected: %w\", issueID, label, err)\n\t}\n\tif rows == 0 {\n\t\tissueTable := \"issues\"\n\t\tif opts.UseWispsTable {\n\t\t\tissueTable = \"wisps\"\n\t\t}\n\t\tvar count int\n\t\t//nolint:gosec // G201: issueTable is one of two hardcoded constants.\n\t\tif err := r.runner.QueryRowContext(ctx, fmt.Sprintf(\"SELECT COUNT(*) FROM %s WHERE id = ?\", issueTable), issueID).Scan(&count); err != nil {\n\t\t\treturn fmt.Errorf(\"db: LabelSQLRepository.Insert %s/%s: verify issue: %w\", issueID, label, err)\n\t\t}\n\t\tif count == 0 {\n\t\t\treturn fmt.Errorf(\"db: LabelSQLRepository.Insert %s/%s: issue does not exist\", issueID, label)\n\t\t}\n\t\treturn nil\n\t}\n\tif err := r.events.Record(ctx, domain.Event{\n\t\tIssueID:  issueID,\n\t\tType:     types.EventLabelAdded,\n\t\tActor:    actor,\n\t\tNewValue: label,\n\t}, domain.RecordEventOpts{UseWispsTable: opts.UseWispsTable}); err != nil {\n\t\treturn err\n\t}\n\t// A label is part of the bead snapshot; the idempotent no-op path above\n\t// returns without writing and journals nothing.\n\treturn issueops.RecordEventInTx(ctx, r.runner, issueops.EventUpdate, issueID, actor)\n}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/label.go#L52-L88","documentation":"Thrown when the repository's follow-up verification SELECT COUNT(*) on the parent issue (in `issues` or `wisps`) fails after INSERT IGNORE reported 0 rows affected. This means 0 rows were inserted AND the existence check itself errored, so the repository cannot distinguish a missing issue from a DB problem.","triggerScenarios":"Insert called with an issueID that yields 0 affected rows (duplicate label or truly missing issue) and the verification query hits a DB error (connection loss, wrong table, permissions).","commonSituations":"UseWispsTable set but the `wisps` table does not exist in the database; connection dropped between insert and verify; insufficient SELECT privileges.","solutions":["Inspect the wrapped driver error for the root cause","Verify the queried table (`issues` or `wisps`) exists in this database","Confirm the correct UseWispsTable option matches your storage mode","Re-run the operation after restoring connectivity"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var n int\nerr := db.QueryRowContext(ctx, \"SELECT COUNT(*) FROM wisps WHERE id = ?\", issueID).Scan(&n)\nif err != nil { return err }\nif n == 0 { return fmt.Errorf(\"issue %s does not exist\", issueID) }","typeGuard":"func isMissingTableErr(err error) bool { var e *mysql.MySQLError; return errors.As(err, &e) && e.Number == 1146 }","tryCatchPattern":"if err := repo.Insert(ctx, issueID, label, opts); err != nil {\n    var sqle *mysql.MySQLError\n    if errors.As(err, &sqle) && sqle.Number == 1146 { log.Error(\"labels/verify table missing; run migrations\") }\n    return err\n}","preventionTips":["Pre-check the issue exists before labeling","Run schema migrations before using the DB","Match UseWispsTable to your storage mode","Grant SELECT privileges to the app user"],"tags":["database","sql","verification"],"backgroundTag":"sql-verify-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}