{"record":{"id":"1fe226783003bf27","repo":"evanw/esbuild","slug":"invalid-engine-name","errorCode":null,"errorMessage":"Invalid engine name","messagePattern":"Invalid engine name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_js_table.go","lineNumber":48,"sourceCode":"\t\treturn compat.Edge\n\tcase EngineFirefox:\n\t\treturn compat.Firefox\n\tcase EngineHermes:\n\t\treturn compat.Hermes\n\tcase EngineIE:\n\t\treturn compat.IE\n\tcase EngineIOS:\n\t\treturn compat.IOS\n\tcase EngineNode:\n\t\treturn compat.Node\n\tcase EngineOpera:\n\t\treturn compat.Opera\n\tcase EngineRhino:\n\t\treturn compat.Rhino\n\tcase EngineSafari:\n\t\treturn compat.Safari\n\tdefault:\n\t\tpanic(\"Invalid engine name\")\n\t}\n}\n","sourceCodeStart":30,"sourceCodeEnd":51,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_js_table.go#L30-L51","documentation":"convertEngineName (pkg/api/api_js_table.go:48) panics when an EngineName passed in BuildOptions.Engines[i].Name is not one of the 11 declared iota constants (EngineChrome, EngineDeno, EngineEdge, EngineFirefox, EngineHermes, EngineIE, EngineIOS, EngineNode, EngineOpera, EngineRhino, EngineSafari). The file is auto-generated by js_table.ts; the panic indicates the public enum and the generated switch are out of sync, or a caller injected an Engine with a numeric Name from outside the declared set.","triggerScenarios":"Constructing an Engine literal with `Name: api.EngineName(N)` for N outside 0..10, deserializing Engines from JSON where Name is a number, or running a generated bridge whose js_table.ts predates a renumbering/addition of an engine constant. Reached via validateFeatures when iterating Engines.","commonSituations":"Code generators or cgo bindings that hand-build Engine structs, version skew between the auto-generated table and a hand-edited wrapper, or attempting to add a new engine by writing an integer instead of extending the enum and regenerating the table.","solutions":["Construct Engine values using only the declared api.Engine* constants (Chrome, Deno, Edge, Firefox, Hermes, IE, IOS, Node, Opera, Rhino, Safari).","Bounds-check any externally supplied integer against 0..10 before casting to EngineName.","Map engine names from strings at the application boundary and reject unknown ones explicitly.","After adding/removing an engine, regenerate pkg/api/api_js_table.go from js_table.ts and rebuild everything that links the Go core."],"exampleFix":"// before\nengines := []api.Engine{{Name: api.EngineName(20), Version: \"100\"}}\nopts := api.BuildOptions{Engines: engines}\n\n// after\nengines := []api.Engine{{Name: api.EngineNode, Version: \"20\"}}\nopts := api.BuildOptions{Engines: engines}","handlingStrategy":"validation","validationCode":"func checkEngineName(n api.EngineName) error {\n    switch n {\n    case api.EngineChrome, api.EngineDeno, api.EngineEdge, api.EngineFirefox,\n        api.EngineHermes, api.EngineIE, api.EngineIOS, api.EngineNode,\n        api.EngineOpera, api.EngineRhino, api.EngineSafari:\n        return nil\n    }\n    return fmt.Errorf(\"invalid engine name %d (want 0..10)\", uint8(n))\n}\n\nfor i, e := range opts.Engines {\n    if err := checkEngineName(e.Name); err != nil { return fmt.Errorf(\"engines[%d]: %w\", i, err) }\n}","typeGuard":"func isValidEngineName(n api.EngineName) bool {\n    switch n {\n    case api.EngineChrome, api.EngineDeno, api.EngineEdge, api.EngineFirefox,\n        api.EngineHermes, api.EngineIE, api.EngineIOS, api.EngineNode,\n        api.EngineOpera, api.EngineRhino, api.EngineSafari:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Construct Engine values only with declared api.Engine* constants.","Because api_js_table.go is auto-generated, regenerate it from js_table.ts whenever you add or reorder engines, then rebuild everything that links the core.","Map engine names from strings at the application boundary and reject unknown ones.","Bounds-check integers from inter-process sources to 0..10."],"tags":["esbuild","config","validation","panic","engine","generated","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}