matryer/xbar · error
malformed xbar.var format
Error message
malformed xbar.var format
What it means
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.
Source
Thrown at pkg/metadata/plugin_metadata.go:379
}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(pluginsWithImages), func(i, j int) {
pluginsWithImages[i], pluginsWithImages[j] = pluginsWithImages[j], pluginsWithImages[i]
})
return pluginsWithImages[:n]
}
func parsePluginVar(s string) (PluginVar, error) {
var v PluginVar
varLineRegexp, err := regexp.Compile(`(.+)\((.+)\):\s(.+)`)
if err != nil {
return v, errors.Wrap(err, "var line regexp")
}
segments := varLineRegexp.FindAllStringSubmatch(s, -1)
if len(segments) != 1 {
return v, errParse{
src: s,
err: errors.New("malformed xbar.var format"),
}
}
if len(segments[0]) != 4 {
return v, errParse{
src: s,
err: errors.New("malformed xbar.var format"),
}
}
segs := segments[0]
v.Type = segs[1]
v.Desc = segs[3]
v.Name = segs[2]
if strings.Contains(v.Name, "=") {
nameSegs := strings.Split(v.Name, "=")
v.Name = nameSegs[0]
v.Default = strings.Trim(nameSegs[1], `"'`)
}
v.Label = v.NameView on GitHub (pinned to d624239058)
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
Example fix
// before // <xbar.var>string(VAR_API_KEY)</xbar.var> // after // <xbar.var>string(VAR_API_KEY): Your API key.</xbar.var>
Defensive patterns
Strategy: validation
Validate before calling
var varLineRe = regexp.MustCompile(`^<xbar\.var>(.+)\((.+)\):\s(.+)</xbar\.var>$`)
func isWellFormedVarLine(line string) bool {
return varLineRe.MatchString(strings.TrimSpace(line))
} Type guard
func isParsableVar(line string) bool {
_, err := regexp.Compile(`(.+)\((.+)\):\s(.+)`)
if err != nil {
return false
}
return len(regexp.MustCompile(`(.+)\((.+)\):\s(.+)`).FindAllStringSubmatch(line, -1)) == 1
} Try / catch
v, err := metadata.Parse(src)
if err != nil {
var ep metadata.ErrParse // or use errors.As on the concrete errParse type
if errors.As(err, &ep) && strings.Contains(err.Error(), "malformed xbar.var format") {
log.Printf("fix this var line: %s", ep.Src)
return
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- malformed xbar.var format (missing select options)
- malformed xbar.var format (empty select options)
- metadata.Parse
- not an xbar:// url
- unsupported action %q
AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02).
Data as JSON: /api/errors/60b5c5e61a1ec4bf.
Report an issue: GitHub.