matryer/xbar · error

malformed xbar.var format (default not in select options)

Error message

malformed xbar.var format (default not in select options)

What it means

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.

Source

Thrown at pkg/metadata/plugin_metadata.go:440

			v.Options = append(v.Options, cleanStr)
		}
		if len(v.Options) == 0 {
			return v, errParse{
				src: s,
				err: errors.New("malformed xbar.var format (empty select options)"),
			}
		}
		defaultFound := false
		for _, val := range v.Options {
			if val == v.Default {
				defaultFound = true
				break
			}
		}
		if !defaultFound {
			return v, errParse{
				src: s,
				err: errors.New("malformed xbar.var format (default not in select options)"),
			}
		}
	default: // invalid type
		return v, errors.Errorf("unknown xbar.var type: %s", v.Type)
	}
	return v, nil
}

type errMissingMetadata string

func (e errMissingMetadata) Error() string {
	return fmt.Sprintf("missing <%[1]s></%[1]s>", string(e))
}

type errParse struct {
	src string
	err error
}

View on GitHub (pinned to d624239058)

Solutions

  1. Add the default value to the select options list in the xbar.var comment
  2. Change the default value to one of the existing select options
  3. Reformat the xbar.var comment to the valid `select(VAR_NAME="default"): opt1, opt2` shape

Example fix

// before
// <xbar.var>select(VAR_THEME="dark"): light</xbar.var>
// after
// <xbar.var>select(VAR_THEME="dark"): light, dark</xbar.var>
Defensive patterns

Strategy: validation

Validate before calling

// before Parse: check every select var default is in its options
re := regexp.MustCompile(`select\(\w+="([^"]*)"\)[^:]*:([^<]*)</xbar.var>`)
for _, m := range re.FindAllStringSubmatch(pluginSrc, -1) {
    def, opts := m[1], strings.Split(m[2], ",")
    found := false
    for _, o := range opts {
        if strings.TrimSpace(o) == def {
            found = true
        }
    }
    if !found {
        return fmt.Errorf("select default %q not in options", def)
    }
}

Try / catch

// Go: inspect the returned errParse
p, err := meta.Parse(src)
if err != nil {
    var ep metadata.ErrParse
    if errors.As(err, &ep) {
        log.Printf("bad xbar.var source: %s", ep.Src)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02). Data as JSON: /api/errors/f602afb43f01dc98. Report an issue: GitHub.