{"record":{"id":"2625681ecb2a5b9f","repo":"matryer/xbar","slug":"load-default-vars","errorCode":null,"errorMessage":"load default vars","messagePattern":"load default vars","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/plugins/variables.go","lineNumber":85,"sourceCode":"}\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)\n\tgo func() {\n\t\tjsonFileVars, jsonFileVarsErr = p.loadVariablesFromJSONFile()\n\t\twg.Done()\n\t}()\n\twg.Wait()\n\tif defaultVarsErr != nil {\n\t\treturn nil, errors.Wrap(defaultVarsErr, \"load default vars\")\n\t}\n\tif jsonFileVarsErr != nil {\n\t\treturn nil, errors.Wrap(jsonFileVarsErr, \"load json file vars\")\n\t}\n\t// add the json file vars to the defaults,\n\t// and return them.\n\tfor k, v := range jsonFileVars {\n\t\tdefaultVars[k] = v\n\t}\n\treturn defaultVars, nil\n}\n\n// loadVariablesFromJSONFile gets a list of environment variable friendly\n// key=value pairs.\nfunc (p *Plugin) loadVariablesFromJSONFile() (map[string]interface{}, error) {\n\tvariablesJSONFilename := p.Command + variableJSONFileExt\n\tf, err := os.Open(variablesJSONFilename)\n\tif err != nil && os.IsNotExist(err) {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/variables.go#L67-L103","documentation":"loadVariables (pkg/plugins/variables.go:84-85) wraps errors from loadVariablesFromPluginMetadata (run in a goroutine) with 'load default vars'. It means the plugin's own source file could not be read or its metadata parsed, so default variable values cannot be established. Reported as 'load default vars: open plugin source: ...' or '... metadata.Parse: ...'.","triggerScenarios":"p.Command (the plugin executable path) does not exist or is unreadable; the file exceeds the 1MB read limit path fails; metadata.Parse rejects malformed `<xbar.var>` declarations in the plugin script.","commonSituations":"The plugin binary was deleted/updated while its .vars.json remains; user installed a plugin from an untrusted source with broken var annotations; path with spaces or moved installation directory invalidates p.Command.","solutions":["Reinstall or restore the plugin so p.Command points to an existing readable file.","Check the plugin source's `<xbar.var>` header annotations for syntax errors and fix them.","Use errors %+v formatting to see the full chain and identify whether it failed at open, read, or metadata.Parse.","Re-save plugin variables from the settings UI after repairing the plugin."],"exampleFix":"// before\nif _, err := os.Stat(p.Command); err != nil {\n\treturn fmt.Errorf(\"plugin missing: %w\", err)\n}\n// after — skip stale plugins gracefully\nif _, err := os.Stat(p.Command); err != nil {\n\tp.Debugf(\"skipping plugin %s: %v\", p.CleanFilename(), err)\n\treturn nil\n}","handlingStrategy":"fallback","validationCode":"if info, err := os.Stat(p.Command); err != nil {\n\tlog.Printf(\"default vars unavailable: plugin source missing: %v\", err)\n} else if !info.Mode().IsRegular() || info.Mode().Perm()&0400 == 0 {\n\tlog.Printf(\"plugin source not a readable regular file\")\n}","typeGuard":null,"tryCatchPattern":"vars, err := p.loadVariables()\nif err != nil {\n\tvar wrappedErr error\n\tif errors.As(err, &wrappedErr) && strings.Contains(err.Error(), \"load default vars\") {\n\t\tlog.Printf(\"metadata defaults failed, using saved vars only: %+v\", err)\n\t\treturn p.loadVariablesFromJSONFile()\n\t}\n\treturn nil, err\n}","preventionTips":["Keep plugin executables installed at stable paths; reinstall instead of hand-moving files.","Validate plugin metadata annotations at install time.","Re-check plugin integrity (file exists + readable) after app updates.","Warn users when an upgrade replaces a plugin whose vars they customized."],"tags":["go","plugins","metadata","missing-file"],"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"}