{"record":{"id":"60b5c5e61a1ec4bf","repo":"matryer/xbar","slug":"malformed-xbar-var-format","errorCode":null,"errorMessage":"malformed xbar.var format","messagePattern":"malformed xbar\\.var format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/metadata/plugin_metadata.go","lineNumber":379,"sourceCode":"\t}\n\trand.Seed(time.Now().UnixNano())\n\trand.Shuffle(len(pluginsWithImages), func(i, j int) {\n\t\tpluginsWithImages[i], pluginsWithImages[j] = pluginsWithImages[j], pluginsWithImages[i]\n\t})\n\treturn pluginsWithImages[:n]\n}\n\nfunc parsePluginVar(s string) (PluginVar, error) {\n\tvar v PluginVar\n\tvarLineRegexp, err := regexp.Compile(`(.+)\\((.+)\\):\\s(.+)`)\n\tif err != nil {\n\t\treturn v, errors.Wrap(err, \"var line regexp\")\n\t}\n\tsegments := varLineRegexp.FindAllStringSubmatch(s, -1)\n\tif len(segments) != 1 {\n\t\treturn v, errParse{\n\t\t\tsrc: s,\n\t\t\terr: errors.New(\"malformed xbar.var format\"),\n\t\t}\n\t}\n\tif len(segments[0]) != 4 {\n\t\treturn v, errParse{\n\t\t\tsrc: s,\n\t\t\terr: errors.New(\"malformed xbar.var format\"),\n\t\t}\n\t}\n\tsegs := segments[0]\n\tv.Type = segs[1]\n\tv.Desc = segs[3]\n\tv.Name = segs[2]\n\tif strings.Contains(v.Name, \"=\") {\n\t\tnameSegs := strings.Split(v.Name, \"=\")\n\t\tv.Name = nameSegs[0]\n\t\tv.Default = strings.Trim(nameSegs[1], `\"'`)\n\t}\n\tv.Label = v.Name","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/metadata/plugin_metadata.go#L361-L397","documentation":"parsePluginVar parses an <xbar.var> metadata line using the regexp (.+)\\((.+)\\):\\s(.+), which must match exactly once and yield exactly 4 submatches (whole line + type + name + desc). If the line doesn't match exactly one time, a malformed-format errParse is returned wrapping the raw source line so the author can fix it.","triggerScenarios":"Parse encounters an xbar.var line that doesn't fit '<TYPE>(<NAME>[=default]): <desc>' — e.g. \"<xbar.var>string(VAR_NAME)</xbar.var>\" (missing colon+desc), \"<xbar.var>string VAR_NAME: desc</xbar.var>\" (missing parens), or a line with two xbar.var elements on one source string giving 2 matches.","commonSituations":"Hand-written var lines missing the colon or description; nested/multiple var declarations on one line; copy-paste losing the ': ' separator; smart quotes or unicode characters breaking the match; trailing whitespace inside the tag confusing the regex.","solutions":["Rewrite the var line in the canonical form: <xbar.var>string(VAR_NAME): Description.</xbar.var>","Ensure exactly one xbar.var declaration per line with matching parentheses and a ': ' before the description","Include a non-empty description after the colon — the regex requires whitespace then text","Re-run Parse and check the errParse.src field to see the exact offending line"],"exampleFix":"// before\n// <xbar.var>string(VAR_API_KEY)</xbar.var>\n// after\n// <xbar.var>string(VAR_API_KEY): Your API key.</xbar.var>","handlingStrategy":"validation","validationCode":"var varLineRe = regexp.MustCompile(`^<xbar\\.var>(.+)\\((.+)\\):\\s(.+)</xbar\\.var>$`)\n\nfunc isWellFormedVarLine(line string) bool {\n\treturn varLineRe.MatchString(strings.TrimSpace(line))\n}","typeGuard":"func isParsableVar(line string) bool {\n\t_, err := regexp.Compile(`(.+)\\((.+)\\):\\s(.+)`)\n\tif err != nil {\n\t\treturn false\n\t}\n\treturn len(regexp.MustCompile(`(.+)\\((.+)\\):\\s(.+)`).FindAllStringSubmatch(line, -1)) == 1\n}","tryCatchPattern":"v, err := metadata.Parse(src)\nif err != nil {\n\tvar ep metadata.ErrParse // or use errors.As on the concrete errParse type\n\tif errors.As(err, &ep) && strings.Contains(err.Error(), \"malformed xbar.var format\") {\n\t\tlog.Printf(\"fix this var line: %s\", ep.Src)\n\t\treturn\n\t}\n\treturn err\n}","preventionTips":["Follow the exact syntax: <xbar.var>TYPE(NAME=default): Description. [opts]</xbar.var>","One xbar.var declaration per line only","Always include ': ' and a non-empty description","Avoid literal parentheses inside the description"],"tags":["metadata","parsing","xbar-var","regex","go"],"backgroundTag":"malformed-var-declaration","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}