{"record":{"id":"a48cc96ae0556183","repo":"matryer/xbar","slug":"metadata-parse","errorCode":null,"errorMessage":"metadata.Parse","messagePattern":"metadata\\.Parse","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/plugins/variables.go","lineNumber":134,"sourceCode":"\t\treturn nil, errors.Wrap(err, \"json.Unmarshal\")\n\t}\n\treturn vars, nil\n}\n\nfunc (p *Plugin) loadVariablesFromPluginMetadata() (map[string]interface{}, error) {\n\t// read the plugin metadata for default values\n\tpluginFile, err := os.Open(p.Command)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"open plugin source\")\n\t}\n\tdefer pluginFile.Close()\n\tpluginFileB, err := io.ReadAll(io.LimitReader(pluginFile, 1_000_000))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"read plugin source\")\n\t}\n\tpluginMetadata, err := metadata.Parse(metadata.DebugFunc(p.Debugf), p.CleanFilename(), string(pluginFileB))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"metadata.Parse\")\n\t}\n\tvars := make(map[string]interface{})\n\tfor _, pluginVar := range pluginMetadata.Vars {\n\t\tif pluginVar.Default == \"\" {\n\t\t\t// skip values with no default\n\t\t\tcontinue\n\t\t}\n\t\tvars[pluginVar.Name] = pluginVar.DefaultValue()\n\t}\n\treturn vars, nil\n}\n","sourceCodeStart":116,"sourceCodeEnd":146,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/variables.go#L116-L146","documentation":"This error is wrapped when metadata.Parse fails to parse the plugin's metadata (embedded #!/bin/... shebang script with metadata comments) from the plugin file's contents. It means the file was read fine, but its metadata section (name, version, vars) is malformed or unsupported. The library wraps it so callers know variable loading failed at the parse stage.","triggerScenarios":"loadVariablesFromPluginMetadata calls metadata.Parse(debugFunc, p.CleanFilename(), string(pluginFileB)) (pkg/plugins/variables.go:134) and the parser rejects the content — e.g. missing/invalid shebang, malformed metadata comment block, unparseable variable declarations, empty or non-plugin file.","commonSituations":"Hand-edited plugin script broke the metadata comment syntax; plugin from an older/newer version uses metadata format the parser rejects; file is empty (0 bytes) or a binary without expected metadata; wrong file extension/filename confusing CleanFilename; truncated download (cut at 1MB LimitReader) slicing the metadata block.","solutions":["Inspect the plugin file's header/metadata comments and fix syntax to match the expected metadata format","Verify the file is non-empty and a valid plugin script (correct shebang, complete metadata block)","Reinstall/re-download the plugin — the file may be truncated or corrupted","Check the plugin was written for a compatible version of this library (metadata format changes across versions)","Enable p.Debugf / metadata.DebugFunc to see the parser's specific complaint"],"exampleFix":"// before (malformed header)\n#!/bin/bash\n# name: myplugin\nvars: FOO=${FOO:-}\n// after (valid metadata block)\n#!/bin/bash\n# name: myplugin\n# version: 1.0.0\n# foo: description of foo\n# FOO: ${FOO:-default}","handlingStrategy":"validation","validationCode":"func hasValidPluginHeader(path string) error {\n\tb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(b) == 0 {\n\t\treturn fmt.Errorf(\"plugin %s is empty\", path)\n\t}\n\tif !bytes.HasPrefix(b, []byte(\"#!\")) {\n\t\treturn fmt.Errorf(\"plugin %s missing shebang\", path)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"vars, err := loadVariablesFromPluginMetadata(p)\nif err != nil {\n\tif strings.Contains(fmt.Sprintf(\"%+v\", err), \"metadata.Parse\") {\n\t\tlog.Printf(\"invalid plugin metadata in %s: %v\", p.CleanFilename(), err)\n\t\treturn map[string]interface{}{}, nil\n\t}\n\treturn nil, err\n}","preventionTips":["Lint plugin scripts' metadata blocks in CI before distribution","Never hand-edit plugin metadata comments without validating against the parser","Pin plugin files to versions compatible with the library's metadata format","Verify downloads (checksum/size) so truncated files are rejected before parsing"],"tags":["go","plugins","parsing","metadata"],"backgroundTag":"metadata-parse-failed","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}