{"id":"d8ab793b8cd64def","repo":"evanw/esbuild","slug":"invalid-legal-comments","errorCode":null,"errorMessage":"Invalid legal comments","messagePattern":"Invalid legal comments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":172,"sourceCode":"\tswitch value {\n\tcase LegalCommentsDefault:\n\t\tif bundle {\n\t\t\treturn config.LegalCommentsEndOfFile\n\t\t} else {\n\t\t\treturn config.LegalCommentsInline\n\t\t}\n\tcase LegalCommentsNone:\n\t\treturn config.LegalCommentsNone\n\tcase LegalCommentsInline:\n\t\treturn config.LegalCommentsInline\n\tcase LegalCommentsEndOfFile:\n\t\treturn config.LegalCommentsEndOfFile\n\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 {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L154-L190","documentation":"A panic raised by validateLegalComments when the LegalComments value is not one of LegalCommentsDefault/None/Inline/EndOfFile/Linked/External. Reachable only through Go-API misuse that constructs an out-of-range enum value; the JS API's typed union prevents it.","triggerScenarios":"Go API: BuildOptions.LegalComments = LegalComments(9). The JS API maps the option's string union to valid constants internally and cannot trigger the panic.","commonSituations":"Reflective config loading; vendoring drift between fork and upstream enum ordinals; unsafe struct copying across esbuild versions.","solutions":["Use only the documented LegalComments constants.","Guard external deserialization with a switch defaulting to LegalCommentsDefault.","Avoid casting raw integers to LegalComments.","Pin esbuild to a single version across your dependency graph."],"exampleFix":"// before\nopts.LegalComments = api.LegalComments(9)\n\n// after\nopts.LegalComments = api.LegalCommentsEndOfFile","handlingStrategy":"type-guard","validationCode":"func validLegalComments(l api.LegalComments) bool {\n  switch l {\n  case api.LegalCommentsDefault, api.LegalCommentsNone, api.LegalCommentsInline, api.LegalCommentsEndOfFile, api.LegalCommentsLinked, api.LegalCommentsExternal:\n    return true\n  }\n  return false\n}","typeGuard":"type LegalComments = 'none' | 'inline' | 'eof' | 'linked' | 'external'\nfunction isLegalComments(v: unknown): v is LegalComments {\n  return ['none','inline','eof','linked','external'].includes(v as any)\n}","tryCatchPattern":null,"preventionTips":["Use documented LegalComments constants only.","Validate deserialized config values.","Pin a single esbuild version."],"tags":["api","legal-comments","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}