{"record":{"id":"d8ab793b8cd64def","repo":"evanw/esbuild","slug":"invalid-legal-comments","errorCode":null,"errorMessage":"Invalid legal comments","messagePattern":"Invalid legal comments","errorType":"panic","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/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L154-L190","documentation":"validateLegalComments (pkg/api/api_impl.go:172) panics when BuildOptions.LegalComments is outside the enum LegalCommentsDefault(0), LegalCommentsNone(1), LegalCommentsInline(2), LegalCommentsEndOfFile(3), LegalCommentsLinked(4), LegalCommentsExternal(5). The Default branch is resolved using the `bundle` flag (end-of-file when bundling, inline otherwise); any other numeric value has no defined behavior and aborts.","triggerScenarios":"Passing a raw/cast integer for LegalComments, or a deserialized value. Called from validateBuildOptions, so the panic surfaces from api.Build/Context/Transform.","commonSituations":"Config migration scripts that write the field as a number, broken bridges after an esbuild upgrade that added a new enum variant, or code that hand-crafted a BuildOptions literal with an invented constant name.","solutions":["Use api.LegalCommentsDefault (recommended — adapts to bundle mode) or one of None/Inline/EndOfFile/Linked/External.","Validate decoded integers against 0..5 before casting to LegalComments.","Prefer the zero value (LegalCommentsDefault) when in doubt rather than guessing a number.","Rebuild generated/bridge code after re-vendoring esbuild."],"exampleFix":"// before\nopts := api.BuildOptions{LegalComments: api.LegalComments(12), Bundle: true}\n\n// after\nopts := api.BuildOptions{LegalComments: api.LegalCommentsDefault, Bundle: true}","handlingStrategy":"validation","validationCode":"func checkLegalComments(lc api.LegalComments) error {\n    switch lc {\n    case api.LegalCommentsDefault, api.LegalCommentsNone, api.LegalCommentsInline,\n        api.LegalCommentsEndOfFile, api.LegalCommentsLinked, api.LegalCommentsExternal:\n        return nil\n    }\n    return fmt.Errorf(\"invalid legal comments %d (want 0..5)\", uint8(lc))\n}","typeGuard":"func isValidLegalComments(lc api.LegalComments) bool {\n    switch lc {\n    case api.LegalCommentsDefault, api.LegalCommentsNone, api.LegalCommentsInline,\n        api.LegalCommentsEndOfFile, api.LegalCommentsLinked, api.LegalCommentsExternal:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Prefer LegalCommentsDefault — it auto-adapts to bundle mode.","Serialize the choice as a string and translate to a constant at load.","Bounds-check integers from external sources before casting.","Re-vendor the whole stack to one esbuild commit after upgrades."],"tags":["esbuild","config","validation","panic","legal-comments","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}