{"record":{"id":"8105158bb42bd58a","repo":"evanw/esbuild","slug":"invalid-color","errorCode":null,"errorMessage":"Invalid color","messagePattern":"Invalid color","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":185,"sourceCode":"\tcase LegalCommentsLinked:\n\t\treturn config.LegalCommentsLinkedWithComment\n\tcase LegalCommentsExternal:\n\t\treturn config.LegalCommentsExternalWithoutComment\n\tdefault:\n\t\tpanic(\"Invalid legal comments\")\n\t}\n}\n\nfunc validateColor(value StderrColor) logger.UseColor {\n\tswitch value {\n\tcase ColorIfTerminal:\n\t\treturn logger.ColorIfTerminal\n\tcase ColorNever:\n\t\treturn logger.ColorNever\n\tcase ColorAlways:\n\t\treturn logger.ColorAlways\n\tdefault:\n\t\tpanic(\"Invalid color\")\n\t}\n}\n\nfunc validateLogLevel(value LogLevel) logger.LogLevel {\n\tswitch value {\n\tcase LogLevelVerbose:\n\t\treturn logger.LevelVerbose\n\tcase LogLevelDebug:\n\t\treturn logger.LevelDebug\n\tcase LogLevelInfo:\n\t\treturn logger.LevelInfo\n\tcase LogLevelWarning:\n\t\treturn logger.LevelWarning\n\tcase LogLevelError:\n\t\treturn logger.LevelError\n\tcase LogLevelSilent:\n\t\treturn logger.LevelSilent\n\tdefault:","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L167-L203","documentation":"validateColor (pkg/api/api_impl.go:185) panics when StderrColor is not ColorIfTerminal(0), ColorNever(1), or ColorAlways(2). The return value drives logger.UseColor which controls ANSI escape emission in diagnostic output; an unknown value would produce undefined terminal behavior, so esbuild aborts. Called early in contextImpl and Transform option processing.","triggerScenarios":"Assigning Color from a raw integer, an int8/uint8 deserialization, or a bridge that maps a different numbering. The panic occurs while building logger.OutputOptions, before any source file is parsed.","commonSituations":"CLI/JS shims that pass `--color` numeric flags to the Go core with mismatched ordinals, persisted user-preference files that store Color as a number, or tests that hand-craft BuildOptions with `Color: api.StderrColor(9)`.","solutions":["Use api.ColorIfTerminal (default, leave field unset) or api.ColorNever / api.ColorAlways.","Bounds-check any externally supplied integer against 0..2 before casting.","Persist the preference as a string (\"auto\"/\"never\"/\"always\") and map it to the constant at load time.","Re-vendor and rebuild bridges against the same esbuild version."],"exampleFix":"// before\nopts := api.BuildOptions{Color: api.StderrColor(7)}\n\n// after\nopts := api.BuildOptions{Color: api.ColorIfTerminal}","handlingStrategy":"validation","validationCode":"func checkColor(c api.StderrColor) error {\n    switch c {\n    case api.ColorIfTerminal, api.ColorNever, api.ColorAlways:\n        return nil\n    }\n    return fmt.Errorf(\"invalid color %d (want 0..2)\", uint8(c))\n}","typeGuard":"func isValidColor(c api.StderrColor) bool {\n    switch c {\n    case api.ColorIfTerminal, api.ColorNever, api.ColorAlways:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Leave Color unset (zero-value ColorIfTerminal) for normal TTY detection.","Map UI preferences stored as \"auto\"/\"never\"/\"always\" to constants.","Clamp externally supplied integers to 0..2.","Treat any change to the Color enum across an esbuild upgrade as a breaking change for your bridge."],"tags":["esbuild","config","validation","panic","color","logger","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}