{"id":"8105158bb42bd58a","repo":"evanw/esbuild","slug":"invalid-color","errorCode":null,"errorMessage":"Invalid color","messagePattern":"Invalid color","errorType":"validation","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/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L167-L203","documentation":"A panic raised by validateColor when the StderrColor value is not ColorIfTerminal, ColorNever, or ColorAlways. Like the other validate* panics it guards an internal invariant: only Go-API misuse (an out-of-range StderrColor) can reach it.","triggerScenarios":"Go API: BuildOptions.Color = StderrColor(5). The JS API does not expose this option directly in a way that can produce an invalid value.","commonSituations":"Deserializing color from a config file into a raw int; ABI drift between a fork and the public enum; unsafe casts.","solutions":["Use only ColorIfTerminal, ColorNever, or ColorAlways.","Validate external input before assigning to Color.","Re-vendor the official esbuild Go package to restore correct ordinals.","Add a unit test exercising every color mode."],"exampleFix":"// before\nopts.Color = api.StderrColor(5)\n\n// after\nopts.Color = api.ColorIfTerminal","handlingStrategy":"type-guard","validationCode":"func validColor(c api.StderrColor) bool {\n  switch c {\n  case api.ColorIfTerminal, api.ColorNever, api.ColorAlways:\n    return true\n  }\n  return false\n}","typeGuard":"type Color = 'if-terminal' | 'never' | 'always'\nfunction isColor(v: unknown): v is Color {\n  return ['if-terminal','never','always'].includes(v as any)\n}","tryCatchPattern":null,"preventionTips":["Use ColorIfTerminal/ColorNever/ColorAlways only.","Do not cast integers to StderrColor.","Pin a single esbuild version."],"tags":["api","color","panic","invariant","go-api","logging"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}