{"record":{"id":"dd9af55263d6f2ef","repo":"yorukot/superfile","slug":"invalid-background-color-w","errorCode":null,"errorMessage":"invalid background color: %w","messagePattern":"invalid background color: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/file_preview/ansi.go","lineNumber":49,"sourceCode":"\t\t\t// Using the \"▄\" character which fills the lower half\n\t\t\tcell := termenv.String(\"▄\").Foreground(lowerColor).Background(upperColor)\n\t\t\toutput.WriteString(cell.String())\n\t\t}\n\t\t// Only add newline if this is not the last row\n\t\tif y+2 < height {\n\t\t\toutput.WriteByte('\\n')\n\t\t}\n\t}\n\n\treturn output.String()\n}\n\n// Convert image to ansi\nfunc (p *ImagePreviewer) ANSIRenderer(img image.Image, defaultBGColor string,\n\tmaxWidth int, maxHeight int) (string, error) {\n\tbgColor, err := hexToColor(defaultBGColor)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid background color: %w\", err)\n\t}\n\n\t// For ANSI rendering, resize image appropriately\n\tfittedImg := resizeForANSI(img, maxWidth, maxHeight)\n\treturn ConvertImageToANSI(fittedImg, bgColor), nil\n}\n\ntype colorCache struct {\n\trgbaToTermenv map[color.RGBA]termenv.RGBColor\n}\n\nfunc newColorCache() *colorCache {\n\treturn &colorCache{\n\t\trgbaToTermenv: make(map[color.RGBA]termenv.RGBColor),\n\t}\n}\n\nfunc (c *colorCache) getTermenvColor(col color.Color, fallbackColor string) termenv.RGBColor {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/pkg/file_preview/ansi.go#L31-L67","documentation":"ANSIRenderer converts an image to an ANSI art string, first parsing the supplied defaultBGColor via hexToColor. This error wraps hexToColor's failure, meaning the background color string is not a valid hex color (e.g., \"#fff\", \"fff\", or a named color). The rendering cannot proceed without a valid background color.","triggerScenarios":"Calling ImagePreviewWithRenderer (which calls ANSIRenderer) with a defaultBGColor that is not parseable as a hex color — wrong format, empty string, missing '#', or unsupported bit depth.","commonSituations":"User config file contains an invalid bg color value; theme passes a named color like \"black\" instead of \"#000000\"; empty string from an unset config key.","solutions":["Pass a valid 6-digit hex color like \"#000000\" as defaultBGColor","Validate/sanitize the color from user config before calling, falling back to a default on parse failure","Accept 3-digit hex only if hexToColor supports it; otherwise expand \"#fff\" to \"#ffffff\"","Check the wrapped error to confirm it is a parse failure, not a config-loading problem"],"exampleFix":"// before\npreviewer.ANSIRenderer(img, cfg.BGColor, w, h) // cfg.BGColor = \"black\"\n// after\nbg := cfg.BGColor\nif _, err := hexToColor(bg); err != nil {\n\tbg = \"#000000\" // safe default\n}\npreviewer.ANSIRenderer(img, bg, w, h)","handlingStrategy":"validation","validationCode":"func isValidHexColor(s string) bool {\n\t_, err := hexToColor(s)\n\treturn err == nil\n}","typeGuard":null,"tryCatchPattern":"render, err := previewer.ANSIRenderer(img, bg, w, h)\nif err != nil && strings.Contains(err.Error(), \"invalid background color\") {\n\trender, err = previewer.ANSIRenderer(img, \"#000000\", w, h)\n}","preventionTips":["Store only validated hex colors in user config","Normalize 3-digit hex (#fff) to 6-digit before passing","Reject empty or named colors at config load time","Keep a safe default background constant in one shared place"],"tags":["go","ansi","color","image"],"backgroundTag":"invalid-color-format","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}