{"record":{"id":"f602afb43f01dc98","repo":"matryer/xbar","slug":"malformed-xbar-var-format-default-not-in-select-o","errorCode":null,"errorMessage":"malformed xbar.var format (default not in select options)","messagePattern":"malformed xbar\\.var format \\(default not in select options\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/metadata/plugin_metadata.go","lineNumber":440,"sourceCode":"\t\t\tv.Options = append(v.Options, cleanStr)\n\t\t}\n\t\tif len(v.Options) == 0 {\n\t\t\treturn v, errParse{\n\t\t\t\tsrc: s,\n\t\t\t\terr: errors.New(\"malformed xbar.var format (empty select options)\"),\n\t\t\t}\n\t\t}\n\t\tdefaultFound := false\n\t\tfor _, val := range v.Options {\n\t\t\tif val == v.Default {\n\t\t\t\tdefaultFound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !defaultFound {\n\t\t\treturn v, errParse{\n\t\t\t\tsrc: s,\n\t\t\t\terr: errors.New(\"malformed xbar.var format (default not in select options)\"),\n\t\t\t}\n\t\t}\n\tdefault: // invalid type\n\t\treturn v, errors.Errorf(\"unknown xbar.var type: %s\", v.Type)\n\t}\n\treturn v, nil\n}\n\ntype errMissingMetadata string\n\nfunc (e errMissingMetadata) Error() string {\n\treturn fmt.Sprintf(\"missing <%[1]s></%[1]s>\", string(e))\n}\n\ntype errParse struct {\n\tsrc string\n\terr error\n}","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/metadata/plugin_metadata.go#L422-L458","documentation":"parsePluginVar validates xbar.var comment declarations. For vars of type \"select\", the declared default value must exactly match one of the listed option values. If the `<xbar.var>string(VAR_NAME=\"default\"...)` declaration is a select but its default is not present in the options list, parsing fails with an errParse wrapping this message.","triggerScenarios":"Calling Parse (via parsePluginVar) on plugin source containing a select-type xbar.var whose default value is not among the enumerated options, e.g. `<xbar.var>select(VAR_MODE=\"fast\"): slow, medium</xbar.var>` where \"fast\" is not listed.","commonSituations":"Hand-edited plugin metadata where the developer changed the default but forgot to add it to the option list; renaming an option without updating the default; copy-pasting a var template and editing options only.","solutions":["Add the default value to the select options list in the xbar.var comment","Change the default value to one of the existing select options","Reformat the xbar.var comment to the valid `select(VAR_NAME=\"default\"): opt1, opt2` shape"],"exampleFix":"// before\n// <xbar.var>select(VAR_THEME=\"dark\"): light</xbar.var>\n// after\n// <xbar.var>select(VAR_THEME=\"dark\"): light, dark</xbar.var>","handlingStrategy":"validation","validationCode":"// before Parse: check every select var default is in its options\nre := regexp.MustCompile(`select\\(\\w+=\"([^\"]*)\"\\)[^:]*:([^<]*)</xbar.var>`)\nfor _, m := range re.FindAllStringSubmatch(pluginSrc, -1) {\n    def, opts := m[1], strings.Split(m[2], \",\")\n    found := false\n    for _, o := range opts {\n        if strings.TrimSpace(o) == def {\n            found = true\n        }\n    }\n    if !found {\n        return fmt.Errorf(\"select default %q not in options\", def)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go: inspect the returned errParse\np, err := meta.Parse(src)\nif err != nil {\n    var ep metadata.ErrParse\n    if errors.As(err, &ep) {\n        log.Printf(\"bad xbar.var source: %s\", ep.Src)\n    }\n    return err\n}","preventionTips":["Always keep the select default synchronized with the options list","Lint xbar.var comments in CI before publishing","Copy a known-good select declaration template when adding new vars"],"tags":["metadata","parsing","validation","plugins"],"backgroundTag":"enum-default-not-in-options","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}