matryer/xbar · error
loadVariables
Error message
loadVariables
What it means
loadVariablesAsEnvVars (pkg/plugins/variables.go:58-60) wraps any error from p.loadVariables() with 'loadVariables'. loadVariables concurrently reads defaults from plugin metadata and the .vars.json override file; any failure in either source propagates through this wrapper when building the environment variables passed to the plugin process. The message is 'loadVariables: <wrapped cause>'.
Source
Thrown at pkg/plugins/variables.go:60
return nil, errors.Wrap(err, "Open")
}
defer f.Close()
b, err := io.ReadAll(io.LimitReader(f, 1_000_000 /* ~1MB */))
if err != nil {
return nil, errors.Wrap(err, "ReadAll")
}
var values map[string]interface{}
err = json.Unmarshal(b, &values)
if err != nil {
return nil, errors.Wrap(err, "json.Unmarshal")
}
return values, nil
}
func (p *Plugin) loadVariablesAsEnvVars() ([]string, error) {
vars, err := p.loadVariables()
if err != nil {
return nil, errors.Wrap(err, "loadVariables")
}
envvars := make([]string, 0, len(vars))
for k, v := range vars {
envvars = append(envvars, fmt.Sprintf("%s=%v", k, v))
}
return envvars, nil
}
func (p *Plugin) loadVariables() (map[string]interface{}, error) {
var wg sync.WaitGroup
var defaultVars, jsonFileVars map[string]interface{}
var defaultVarsErr, jsonFileVarsErr error
wg.Add(1)
go func() {
defaultVars, defaultVarsErr = p.loadVariablesFromPluginMetadata()
wg.Done()
}()
wg.Add(1)View on GitHub (pinned to d624239058)
Solutions
- Look at the full wrapped chain (errors.Cause / %+v with pkg/errors) to see which sub-step (load default vars / load json file vars) failed.
- Fix the underlying cause: restore the plugin file, repair or delete the .vars.json file, or fix the `<xbar.var>` annotations in the plugin source.
- Verify p.Command points to an existing, readable plugin executable before running.
- Handle this error in the Run path by falling back to defaults or showing the error in the menu bar instead of failing the plugin.
Example fix
// before
envvars, err := p.loadVariablesAsEnvVars()
if err != nil {
return fmt.Errorf("run: %w", err)
}
// after — degrade gracefully
envvars, err := p.loadVariablesAsEnvVars()
if err != nil {
p.Debugf("could not load variables, using none: %v", err)
envvars = nil
} Defensive patterns
Strategy: fallback
Validate before calling
if _, err := os.Stat(p.Command); err != nil {
log.Printf("plugin %s missing, cannot build env vars: %v", p.Command, err)
}
if _, err := os.Stat(p.Command + ".vars.json"); err == nil {
if b, err := os.ReadFile(p.Command + ".vars.json"); err == nil {
var v map[string]interface{}
if err := json.Unmarshal(b, &v); err != nil {
log.Printf("vars json corrupt: %v", err)
}
}
} Try / catch
envvars, err := p.loadVariablesAsEnvVars()
if err != nil {
log.Printf("plugin vars unavailable, running without overrides: %+v", err)
envvars = nil // run the plugin with no variable overrides
} Prevention
- Validate plugin scripts' `<xbar.var>` annotations when installing.
- Clean up stale plugin entries when plugins are uninstalled or moved.
- Log with pkg/errors %+v to expose the full wrap chain for debugging.
- Surface variable-load failures in the UI instead of silently failing the plugin run.
When it happens
Trigger: Running a plugin whose executable/source (p.Command) cannot be read for metadata; the .vars.json file is corrupt or unreadable; metadata.Parse fails on malformed plugin script headers. Any of these bubbles up wrapped as 'loadVariables' when the plugin Run path builds env vars.
Common situations: User deletes or renames the plugin binary after installing variables; plugin script has broken `<xbar.var>` annotations that fail metadata parsing; vars file corrupted by a bad edit — all surface at plugin run time as this error instead of the plugin executing.
Related errors
AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02).
Data as JSON: /api/errors/48301d7439fd74c3.
Report an issue: GitHub.