{"record":{"id":"c2d080fa451d964e","repo":"matryer/xbar","slug":"expected-hex-string-or-named-color","errorCode":null,"errorMessage":"expected hex string or named color","messagePattern":"expected hex string or named color","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/plugins/item_params.go","lineNumber":290,"sourceCode":"\treturn nil\n}\n\n// parseBool parses a boolean from a string (either `true` or `false`),\n// returning a nice error if it fails.\nfunc parseBool(s string) (bool, error) {\n\tb, err := strconv.ParseBool(s)\n\tif err != nil {\n\t\treturn false, errors.Errorf(`expected \"true\" or \"false\", not \"%s\"`, s)\n\t}\n\treturn b, nil\n}\n\n// parseColor parses the color value given.\n// Valid values: named color, #RGB, #RGBA, #RRGGBB, #RRGGBBAA.\n// Returns a nice error if it fails.\nfunc parseColor(s string) (string, error) {\n\tif len(s) == 0 {\n\t\treturn \"\", errors.Errorf(\"expected hex string or named color\") // Probably an error?\n\t}\n\ts = strings.ToLower(s)\n\tif s[0] == '#' {\n\t\t// Matches #RGB #RGBA #RRGGBB #RRGGBBAA\n\t\tif !colorRegexp.Match([]byte(s)) {\n\t\t\treturn \"\", errors.Errorf(`invalid hex format \"%s\"`, s)\n\t\t}\n\t\treturn s, nil\n\t}\n\thexValue, valid := namedColors[s]\n\tif !valid {\n\t\treturn \"\", errors.Errorf(`invalid named color \"%s\"`, s)\n\t}\n\treturn hexValue, nil\n}\n\n// parseInt parses an int from a string, returning a nice\n// error if it fails.","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/item_params.go#L272-L308","documentation":"parseColor validates a plugin-provided color value (named color, #RGB, #RGBA, #RRGGBB or #RRGGBBAA). This error is thrown when the color value is an empty string, i.e. no color was supplied at all. The library needs a non-empty token before it can decide whether it is a hex literal or a named color.","triggerScenarios":"setValueByKey passes an empty string to parseColor — e.g. a plugin script emits a menu parameter like | color= with nothing after the '=', or the value is stripped to empty by upstream trimming.","commonSituations":"Plugin authors omitting the value after 'color=' in menu output; shell variables that expand to empty ($COLOR unset) in the plugin script; accidental trailing 'color=' in the template.","solutions":["Provide a valid color value after the parameter, e.g. | color=#FF0000 or | color=red","In the plugin script, guard against unset variables: use ${COLOR:-#FFFFFF} or skip emitting the parameter when empty","Remove the empty color= parameter entirely if you don't need a custom color"],"exampleFix":"// before\necho \"Item | color=$COLOR\"   # COLOR unset -> color=\n// after\necho \"Item | color=${COLOR:-#FF0000}\"","handlingStrategy":"validation","validationCode":"if color == \"\" {\n    color = \"#FFFFFF\" // default before passing to the parameter pipeline\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never emit a bare 'color=' parameter with no value","Default unset shell variables: ${COLOR:-#FFFFFF}","Omit the parameter entirely when no color is desired"],"tags":["plugins","parameters","color","validation"],"backgroundTag":"missing-parameter-value","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}