{"record":{"id":"80e08353dca347d6","repo":"larksuite/cli","slug":"selector-must-be-primary","errorCode":null,"errorMessage":"selector must be primary","messagePattern":"selector must be primary","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shortcuts/mail/draft/model.go","lineNumber":298,"sourceCode":"\tcase \"add_recipient\", \"remove_recipient\":\n\t\tif !isRecipientField(op.Field) {\n\t\t\treturn fmt.Errorf(\"recipient field must be one of to/cc/bcc\")\n\t\t}\n\t\tif strings.TrimSpace(op.Address) == \"\" {\n\t\t\treturn fmt.Errorf(\"%s requires address\", op.Op)\n\t\t}\n\tcase \"set_reply_to\":\n\t\tif len(op.Addresses) == 0 {\n\t\t\treturn fmt.Errorf(\"set_reply_to requires addresses\")\n\t\t}\n\tcase \"clear_reply_to\":\n\tcase \"set_body\", \"set_reply_body\":\n\tcase \"replace_body\", \"append_body\":\n\t\tif !isBodyKind(op.BodyKind) {\n\t\t\treturn fmt.Errorf(\"body_kind must be text/plain or text/html\")\n\t\t}\n\t\tif op.Selector != \"\" && op.Selector != \"primary\" {\n\t\t\treturn fmt.Errorf(\"selector must be primary\")\n\t\t}\n\tcase \"set_header\":\n\t\tif strings.TrimSpace(op.Name) == \"\" {\n\t\t\treturn fmt.Errorf(\"set_header requires name\")\n\t\t}\n\t\tif strings.ContainsAny(op.Name, \":\\r\\n\") {\n\t\t\treturn fmt.Errorf(\"set_header: header name must not contain ':', CR, or LF\")\n\t\t}\n\t\tif strings.ContainsAny(op.Value, \"\\r\\n\") {\n\t\t\treturn fmt.Errorf(\"set_header: header value must not contain CR or LF\")\n\t\t}\n\tcase \"remove_header\":\n\t\tif strings.TrimSpace(op.Name) == \"\" {\n\t\t\treturn fmt.Errorf(\"remove_header requires name\")\n\t\t}\n\tcase \"add_attachment\":\n\t\tif strings.TrimSpace(op.Path) == \"\" {\n\t\t\treturn fmt.Errorf(\"add_attachment requires path\")","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/shortcuts/mail/draft/model.go#L280-L316","documentation":"Thrown by PatchOp.Validate() in shortcuts/mail/draft/model.go:298 when a replace_body or append_body op has a selector that is neither empty nor exactly \"primary\". The selector identifies which body part to modify; only the \"primary\" body is supported, and empty is treated as \"primary\".","triggerScenarios":"Ops like {\"op\":\"append_body\",\"body_kind\":\"text/html\",\"selector\":\"body\"} or selector:\"main\"/\"all\"; copying a selector value from a different API; leaving a stale selector from another op type in a shared struct.","commonSituations":"Guessing selector names instead of using the documented \"primary\"; reusing a generic patch-builder that sets selector for all ops; thinking an alternative selector targets the alternative/compact body of a message.","solutions":["Remove the selector field entirely (empty defaults to primary).","Set selector to exactly \"primary\" if you want to be explicit.","If you intended to target a different MIME part, note only the primary body is supported by this op."],"exampleFix":"// before\n{\"op\":\"append_body\",\"body_kind\":\"text/html\",\"selector\":\"body\",\"value\":\"<p>x</p>\"}\n\n// after\n{\"op\":\"append_body\",\"body_kind\":\"text/html\",\"value\":\"<p>x</p>\"}","handlingStrategy":"validation","validationCode":"if op.Selector != \"\" && op.Selector != \"primary\" {\n    return fmt.Errorf(\"selector must be empty or \\\"primary\\\", got %q\", op.Selector)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit selector entirely; empty already means primary.","Only \"primary\" is supported — do not guess other part names.","Don't share a generic op builder that sets selector for body ops."],"tags":["mail","validation","patch-op","body"],"backgroundTag":"invalid-enum-value","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}