matryer/xbar · error
load json file vars
Error message
load json file vars
What it means
loadVariables (pkg/plugins/variables.go:87-88) wraps errors from loadVariablesFromJSONFile with 'load json file vars'. The plugin's .vars.json file (p.Command + '.vars.json') exists but could not be opened or its JSON could not be parsed, so user-saved variable overrides are unavailable. Missing files are fine (treated as empty), so this error always means a present-but-broken file.
Source
Thrown at pkg/plugins/variables.go:88
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)
go func() {
jsonFileVars, jsonFileVarsErr = p.loadVariablesFromJSONFile()
wg.Done()
}()
wg.Wait()
if defaultVarsErr != nil {
return nil, errors.Wrap(defaultVarsErr, "load default vars")
}
if jsonFileVarsErr != nil {
return nil, errors.Wrap(jsonFileVarsErr, "load json file vars")
}
// add the json file vars to the defaults,
// and return them.
for k, v := range jsonFileVars {
defaultVars[k] = v
}
return defaultVars, nil
}
// loadVariablesFromJSONFile gets a list of environment variable friendly
// key=value pairs.
func (p *Plugin) loadVariablesFromJSONFile() (map[string]interface{}, error) {
variablesJSONFilename := p.Command + variableJSONFileExt
f, err := os.Open(variablesJSONFilename)
if err != nil && os.IsNotExist(err) {
// no .vars.json file - no probs
return nil, nil
} else if err != nil {View on GitHub (pinned to d624239058)
Solutions
- Validate and fix the JSON in <plugin>.vars.json with a linter/editor.
- Delete the broken .vars.json file — it is optional, and it will be recreated on next save.
- Check file permissions/ownership (chmod 600, chown to your user).
- If it is a directory or placeholder, remove it and re-save variables via the plugin settings UI.
Defensive patterns
Strategy: fallback
Validate before calling
varsPath := p.Command + ".vars.json"
if b, err := os.ReadFile(varsPath); err == nil {
var v map[string]interface{}
if jerr := json.Unmarshal(b, &v); jerr != nil {
log.Printf("%s is not valid JSON, overrides will be ignored: %v", varsPath, jerr)
}
} Try / catch
vars, err := p.loadVariables()
if err != nil && strings.Contains(err.Error(), "load json file vars") {
log.Printf("ignoring broken vars override file: %+v", err)
os.Remove(p.Command + ".vars.json")
vars, err = p.loadVariablesFromPluginMetadata() // fall back to defaults
} Prevention
- Edit .vars.json only with a JSON-aware editor and validate afterwards.
- Treat the vars file as a cache: it is safe to delete and recreate.
- Write it atomically on save to avoid truncated files.
- Exclude *.vars.json from tools that may replace files with placeholders.
When it happens
Trigger: The .vars.json file exists but has invalid JSON (hand-edited, truncated); the file is unreadable due to permissions or is actually a directory; open fails with an error other than IsNotExist at pkg/plugins/variables.go:107.
Common situations: User edits the .vars.json in a text editor and breaks the JSON; interrupted save leaves a truncated file; sync tools replace the file with a placeholder; file owned by root after running as sudo once.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02).
Data as JSON: /api/errors/63e5f2d5a2d73f32.
Report an issue: GitHub.