{"record":{"id":"b5604ab734b19e86","repo":"evanw/esbuild","slug":"invalid-log-level","errorCode":null,"errorMessage":"Invalid log level","messagePattern":"Invalid log level","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":204,"sourceCode":"\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:\n\t\tpanic(\"Invalid log level\")\n\t}\n}\n\nfunc validateLogStyle(value LogStyle) logger.LogStyle {\n\tswitch value {\n\tcase LogStyleDefault:\n\t\treturn logger.StyleDefault\n\tcase LogStyleClang:\n\t\treturn logger.StyleClang\n\tcase LogStyleVisualStudio:\n\t\treturn logger.StyleVisualStudio\n\tdefault:\n\t\tpanic(\"Invalid log style\")\n\t}\n}\n\nfunc validateASCIIOnly(value Charset) bool {\n\tswitch value {","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L186-L222","documentation":"validateLogLevel (pkg/api/api_impl.go:204) panics when LogLevel is outside LogLevelSilent(0), LogLevelVerbose(1), LogLevelDebug(2), LogLevelInfo(3), LogLevelWarning(4), LogLevelError(5). The chosen level gates which messages the logger keeps; an out-of-range value would yield nondeterministic filtering, so esbuild aborts. The function is called from contextImpl, Transform option setup, and validateLogOverrides.","triggerScenarios":"Passing a numeric LogLevel from a cast, JSON/protobuf decode, or an inter-language bridge whose enumeration ordering differs. Also triggered when LogOverride map values are out of range (validateLogOverrides calls validateLogLevel on each value).","commonSituations":"Configuration UIs that store verbosity as an integer and forget to clamp it, version skew between the JS API and Go core after a re-vendor, or downstream code that aliases a removed constant (e.g. an old `LogLevelOff`).","solutions":["Set LogLevel (and every LogOverride value) via the api.LogLevel* constants only; LogLevelSilent suppresses all output.","Clamp decoded integers to 0..5 before assigning, defaulting to LogLevelInfo when uncertain.","Represent verbosity in serialized config as a string and map it to the constant at load.","Re-pin esbuild to a single version across your stack."],"exampleFix":"// before\nopts := api.BuildOptions{LogLevel: api.LogLevel(11), LogOverride: map[string]api.LogLevel{\"css-syntax-error\": api.LogLevel(9)}}\n\n// after\nopts := api.BuildOptions{LogLevel: api.LogLevelInfo, LogOverride: map[string]api.LogLevel{\"css-syntax-error\": api.LogLevelWarning}}","handlingStrategy":"validation","validationCode":"func checkLogLevel(l api.LogLevel) error {\n    switch l {\n    case api.LogLevelSilent, api.LogLevelVerbose, api.LogLevelDebug,\n        api.LogLevelInfo, api.LogLevelWarning, api.LogLevelError:\n        return nil\n    }\n    return fmt.Errorf(\"invalid log level %d (want 0..5)\", uint8(l))\n}\n\n// also check every value in LogOverride:\nfor k, v := range opts.LogOverride {\n    if err := checkLogLevel(v); err != nil { return fmt.Errorf(\"log override %q: %w\", k, err) }\n}","typeGuard":"func isValidLogLevel(l api.LogLevel) bool {\n    switch l {\n    case api.LogLevelSilent, api.LogLevelVerbose, api.LogLevelDebug,\n        api.LogLevelInfo, api.LogLevelWarning, api.LogLevelError:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Remember LogOverride values are also LogLevels and must be validated.","Clamp UI-supplied verbosity integers to 0..5 before passing them in.","Store verbosity as a string and translate at the boundary.","Default to LogLevelInfo when unsure."],"tags":["esbuild","config","validation","panic","log-level","logger","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}