{"record":{"id":"32eeecc551e9c03c","repo":"gastownhall/beads","slug":"w-apply-batch-item-d-has-unknown-kind-q","errorCode":null,"errorMessage":"%w: apply batch item %d has unknown kind %q","messagePattern":"%w: apply batch item (.+?) has unknown kind %q","errorType":"validation","errorClass":"issueops.ErrValidation","httpStatus":null,"severity":"error","filePath":"internal/storage/batch_apply.go","lineNumber":137,"sourceCode":"\t\t\t\tpayloads++\n\t\t\t}\n\t\t}\n\t\tif payloads != 1 {\n\t\t\treturn nil, fmt.Errorf(\"%w: apply batch item %d must carry exactly one payload, got %d\",\n\t\t\t\tissueops.ErrValidation, i, payloads)\n\t\t}\n\t\tvar matches bool\n\t\tswitch item.Kind {\n\t\tcase issueops.ItemCreate:\n\t\t\tmatches = item.Create != nil\n\t\tcase issueops.ItemUpdate:\n\t\t\tmatches = item.Update != nil\n\t\tcase issueops.ItemClose:\n\t\t\tmatches = item.Close != nil\n\t\tcase issueops.ItemDepAdd:\n\t\t\tmatches = item.DepAdd != nil\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"%w: apply batch item %d has unknown kind %q\", issueops.ErrValidation, i, item.Kind)\n\t\t}\n\t\tif !matches {\n\t\t\treturn nil, fmt.Errorf(\"%w: apply batch item %d is kind %q but carries another kind's payload\",\n\t\t\t\tissueops.ErrValidation, i, item.Kind)\n\t\t}\n\t\tif item.Create == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif item.Create.Issue == nil {\n\t\t\treturn nil, fmt.Errorf(\"%w: apply batch item %d requires an issue\", issueops.ErrValidation, i)\n\t\t}\n\t\tif len(item.Create.Issue.Comments) > 0 || len(item.Create.Issue.Dependencies) > 0 {\n\t\t\treturn nil, fmt.Errorf(\"%w: apply batch item %d must not carry comments or dependencies on the issue; edges are their own items\",\n\t\t\t\tissueops.ErrValidation, i)\n\t\t}\n\t\tif item.Create.Key == \"\" {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/batch_apply.go#L119-L155","documentation":"The item's Kind field must be one of the known kinds (ItemCreate, ItemUpdate, ItemClose, ItemDepAdd). An unrecognized Kind hits the switch's default case and fails with the index and the offending kind string, wrapped with issueops.ErrValidation.","triggerScenarios":"Setting Kind to a typo'd or made-up string (e.g. \"creat\", \"delete\"), or a zero-value Kind when the kind enum uses non-zero string constants.","commonSituations":"Hand-written JSON batches with an invalid kind; code written against an older/newer API where kinds changed; structs built without initializing Kind.","solutions":["Use the exported constants (issueops.ItemCreate, etc.) instead of raw strings.","Fix the kind string to exactly match one of the supported constants.","Check for API version drift if the kind was valid in an older version."],"exampleFix":"// before\nitem := issueops.ApplyBatchItem{Kind: \"create\", Create: cr}\n// after\nitem := issueops.ApplyBatchItem{Kind: issueops.ItemCreate, Create: cr}","handlingStrategy":"validation","validationCode":"switch it.Kind {\ncase issueops.ItemCreate, issueops.ItemUpdate, issueops.ItemClose, issueops.ItemDepAdd:\n    // ok\ndefault:\n    return fmt.Errorf(\"unknown kind %q\", it.Kind)\n}","typeGuard":"func knownKind(k issueops.ItemKind) bool {\n    switch k {\n    case issueops.ItemCreate, issueops.ItemUpdate, issueops.ItemClose, issueops.ItemDepAdd:\n        return true\n    }\n    return false\n}","tryCatchPattern":"_, err := storage.PlanApplyBatch(req)\nif errors.Is(err, issueops.ErrValidation) && strings.Contains(err.Error(), \"unknown kind\") {\n    return fmt.Errorf(\"unsupported batch item kind: %w\", err)\n}","preventionTips":["Always use exported Kind constants, never string literals.","Check the library's kind constants after upgrades for renames.","Reject unknown kinds at deserialization time before planning."],"tags":["validation","batch","enum"],"backgroundTag":"validation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}