{"record":{"id":"069bc805d1a942a1","repo":"matryer/xbar","slug":"invalid-hex-format-s","errorCode":null,"errorMessage":"invalid hex format \"%s\"","messagePattern":"invalid hex format \"(.+?)\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/plugins/item_params.go","lineNumber":296,"sourceCode":"\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.\nfunc parseInt(s string) (int, error) {\n\ti, err := strconv.ParseInt(s, 10, 64)\n\tif err != nil {\n\t\treturn 0, errors.Errorf(`expected an int, not \"%s\"`, s)\n\t}\n\treturn int(i), nil","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/matryer/xbar/blob/d624239058997c80118eaebe2e7f8331b3c765e0/pkg/plugins/item_params.go#L278-L314","documentation":"When a color value starts with '#', parseColor matches it against colorRegexp which only accepts #RGB, #RGBA, #RRGGBB or #RRGGBBAA. This error means the hex string is present but has an invalid shape — wrong number of digits or illegal hex characters.","triggerScenarios":"setValueByKey passes a value beginning with '#' that fails colorRegexp — e.g. #FF (too short), #FFFFFFF (7 digits), #GGHHII (non-hex chars), or a stray '#' with nothing after it.","commonSituations":"Plugin authors writing 3-digit-style shorthand incorrectly (#F0F0), copy-pasting 6-digit colors without '#' handling issues, CSS var(--x) or swatch names accidentally left in place of hex, missing digits after '#'.","solutions":["Use exactly 3, 4, 6 or 8 hex digits after '#', e.g. #FFF, #FF0000, #FF0000FF","Check for non-hex characters (G-Z) in the value","If using a named color, drop the '#' — named colors must not start with '#'"],"exampleFix":"// before\necho \"Item | color=#FF\"        // 2 digits, invalid\n// after\necho \"Item | color=#FF0000\"    // 6-digit hex","handlingStrategy":"validation","validationCode":"var hexRe = regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]|[0-9a-fA-F]{3}([0-9a-fA-F])?)?$|^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`)\nif strings.HasPrefix(color, \"#\") && !hexRe.MatchString(color) {\n    color = \"#000000\" // sanitize before emitting\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use 3, 4, 6 or 8 hex digits after '#'","Validate colors in your script before printing","Prefer 6-digit #RRGGBB for clarity"],"tags":["plugins","parameters","color","hex","validation"],"backgroundTag":"invalid-hex-color-format","analyzedSha":"d624239058997c80118eaebe2e7f8331b3c765e0","analyzedAt":"2026-09-02T22:38:22.007Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}