{"record":{"id":"48301d7439fd74c3","repo":"matryer/xbar","slug":"loadvariables","errorCode":null,"errorMessage":"loadVariables","messagePattern":"loadVariables","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/plugins/variables.go","lineNumber":60,"sourceCode":"\t\treturn nil, errors.Wrap(err, \"Open\")\n\t}\n\tdefer f.Close()\n\tb, err := io.ReadAll(io.LimitReader(f, 1_000_000 /* ~1MB */))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"ReadAll\")\n\t}\n\tvar values map[string]interface{}\n\terr = json.Unmarshal(b, &values)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"json.Unmarshal\")\n\t}\n\treturn values, nil\n}\n\nfunc (p *Plugin) loadVariablesAsEnvVars() ([]string, error) {\n\tvars, err := p.loadVariables()\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"loadVariables\")\n\t}\n\tenvvars := make([]string, 0, len(vars))\n\tfor k, v := range vars {\n\t\tenvvars = append(envvars, fmt.Sprintf(\"%s=%v\", k, v))\n\t}\n\treturn envvars, nil\n}\n\nfunc (p *Plugin) loadVariables() (map[string]interface{}, error) {\n\tvar wg sync.WaitGroup\n\tvar defaultVars, jsonFileVars map[string]interface{}\n\tvar defaultVarsErr, jsonFileVarsErr error\n\twg.Add(1)\n\tgo func() {\n\t\tdefaultVars, defaultVarsErr = p.loadVariablesFromPluginMetadata()\n\t\twg.Done()\n\t}()\n\twg.Add(1)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/variables.go#L42-L78","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nenvvars, err := p.loadVariablesAsEnvVars()\nif err != nil {\n\treturn fmt.Errorf(\"run: %w\", err)\n}\n// after — degrade gracefully\nenvvars, err := p.loadVariablesAsEnvVars()\nif err != nil {\n\tp.Debugf(\"could not load variables, using none: %v\", err)\n\tenvvars = nil\n}","handlingStrategy":"fallback","validationCode":"if _, err := os.Stat(p.Command); err != nil {\n\tlog.Printf(\"plugin %s missing, cannot build env vars: %v\", p.Command, err)\n}\nif _, err := os.Stat(p.Command + \".vars.json\"); err == nil {\n\tif b, err := os.ReadFile(p.Command + \".vars.json\"); err == nil {\n\t\tvar v map[string]interface{}\n\t\tif err := json.Unmarshal(b, &v); err != nil {\n\t\t\tlog.Printf(\"vars json corrupt: %v\", err)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"envvars, err := p.loadVariablesAsEnvVars()\nif err != nil {\n\tlog.Printf(\"plugin vars unavailable, running without overrides: %+v\", err)\n\tenvvars = nil // run the plugin with no variable overrides\n}","preventionTips":["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."],"tags":["go","plugins","environment-variables","error-wrapping"],"backgroundTag":"plugin-variable-load-failed","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}