{"record":{"id":"8364d414d48e8b60","repo":"gastownhall/beads","slug":"failed-to-add-label-s-to-s-w","errorCode":null,"errorMessage":"failed to add label %s to %s: %w","messagePattern":"failed to add label (.+?) to (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/cook.go","lineNumber":919,"sourceCode":"\t// This prevents orphaned issues if label/dependency creation fails.\n\terr := transact(ctx, s, fmt.Sprintf(\"bd: cook formula %s\", protoID), func(tx storage.Transaction) error {\n\t\t// Flatten unregistered step types to task (with a warning) before\n\t\t// inserting, mirroring cloneSubgraphInto (pour). Without this,\n\t\t// PrepareIssueForInsert rejects them with \"invalid issue type\" and\n\t\t// the whole cook --persist transaction rolls back.\n\t\tif err := flattenUnregisteredIssueTypes(ctx, storeMolWriter{DoltStorage: s, tx: tx}, issues, deps); err != nil {\n\t\t\treturn fmt.Errorf(\"checking custom types: %w\", err)\n\t\t}\n\n\t\t// Create all issues\n\t\tif err := tx.CreateIssues(ctx, issues, actor); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create issues: %w\", err)\n\t\t}\n\n\t\t// Add labels\n\t\tfor _, l := range labels {\n\t\t\tif err := tx.AddLabel(ctx, l.issueID, l.label, actor); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to add label %s to %s: %w\", l.label, l.issueID, err)\n\t\t\t}\n\t\t}\n\n\t\t// Add dependencies\n\t\tfor _, dep := range deps {\n\t\t\tif err := tx.AddDependency(ctx, dep, actor); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create dependency: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &cookFormulaResult{","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/cook.go#L901-L937","documentation":"Wraps a failure from tx.AddLabel while attaching labels to freshly cooked issues inside the cook --persist transaction. If any label cannot be added, the error names both the label and the target issue ID, and the transaction rolls back, undoing the issue creation as well.","triggerScenarios":"tx.AddLabel returns an error for a generated issue: target issue ID not found in the transaction (unlikely since just created), label violates validation/format rules, duplicate label rejected, or storage-level failure.","commonSituations":"Label strings generated from formula metadata contain invalid characters or exceed length limits; database/storage error mid-transaction; concurrent modification of the issue outside the transaction.","solutions":["Read label and issue ID from the message; check the label string for invalid characters or length and fix it in the formula's labels block","Verify the label is not rejected as a duplicate if the store enforces uniqueness","Check database health if the failure is storage-level (`bd doctor`)","Retry after transient errors — the transaction rollback leaves no partial labels"],"exampleFix":"# before (formula labels block)\nlabels: [\"very long label with  spaces & symbols!\"]\n# after\nlabels: [\"review-needed\"]","handlingStrategy":"try-catch","validationCode":"// Validate label strings before the transaction\nfor _, l := range labels {\n    if strings.TrimSpace(l.label) == \"\" || len(l.label) > 64 {\n        return fmt.Errorf(\"invalid label %q for %s\", l.label, l.issueID)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := tx.AddLabel(ctx, l.issueID, l.label, actor); err != nil {\n    return fmt.Errorf(\"failed to add label %s to %s: %w\", l.label, l.issueID, err)\n}\n// at call site:\nif strings.Contains(err.Error(), \"failed to add label\") {\n    // message names the label and issue; sanitize label in the formula and re-run\n}","preventionTips":["Keep labels short, lowercase-kebab, free of special characters","Review labels blocks in formula YAML after edits","Ignore duplicate-label errors if the store permits duplicates idempotently","Re-run cook --persist after fixing; rollback guarantees no partial labels linger"],"tags":["transaction","labels","persist"],"backgroundTag":"label-add-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}