evanw/esbuild · critical
Invalid log style
Error message
Invalid log style
What it means
validateLogStyle (pkg/api/api_impl.go:217) panics when LogStyle is not LogStyleDefault(0), LogStyleClang(1), or LogStyleVisualStudio(2). The style controls the diagnostic message formatting (file:line:column layout) emitted by the logger; an undefined value would corrupt error output, so esbuild aborts. Reached from contextImpl while constructing logger.OutputOptions.
Source
Thrown at pkg/api/api_impl.go:217
case LogLevelError:
return logger.LevelError
case LogLevelSilent:
return logger.LevelSilent
default:
panic("Invalid log level")
}
}
func validateLogStyle(value LogStyle) logger.LogStyle {
switch value {
case LogStyleDefault:
return logger.StyleDefault
case LogStyleClang:
return logger.StyleClang
case LogStyleVisualStudio:
return logger.StyleVisualStudio
default:
panic("Invalid log style")
}
}
func validateASCIIOnly(value Charset) bool {
switch value {
case CharsetDefault, CharsetASCII:
return true
case CharsetUTF8:
return false
default:
panic("Invalid charset")
}
}
func validateExternalPackages(value Packages) bool {
switch value {
case PackagesDefault, PackagesBundle:
return falseView on GitHub (pinned to f6058f8364)
Solutions
- Use api.LogStyleDefault (zero value) or api.LogStyleClang / api.LogStyleVisualStudio.
- Bounds-check any integer destined for LogStyle against 0..2.
- Store the preference as a string and map to the constant at load.
- Keep esbuild versions aligned across all consumers of the API.
Example fix
// before
opts := api.BuildOptions{LogStyle: api.LogStyle(5)}
// after
opts := api.BuildOptions{LogStyle: api.LogStyleDefault} Defensive patterns
Strategy: validation
Validate before calling
func checkLogStyle(ls api.LogStyle) error {
switch ls {
case api.LogStyleDefault, api.LogStyleClang, api.LogStyleVisualStudio:
return nil
}
return fmt.Errorf("invalid log style %d (want 0..2)", uint8(ls))
} Type guard
func isValidLogStyle(ls api.LogStyle) bool {
switch ls {
case api.LogStyleDefault, api.LogStyleClang, api.LogStyleVisualStudio:
return true
}
return false
} Prevention
- Use the zero value LogStyleDefault unless you specifically need IDE-friendly output.
- Bounds-check integers from inter-process config to 0..2.
- Map editor/IDE preferences to constants rather than passing raw ordinals.
- Re-vendor bridges alongside the core after any esbuild bump.
When it happens
Trigger: Assigning LogStyle from an out-of-range integer, deserializing it from a numeric wire format, or using a stale/imagined constant such as `api.LogStyleMSBuild`. The panic fires during options normalization, before any parsing.
Common situations: Editor/IDE integrations that pipe a `--log-style` flag with a numeric mapping that drifted across versions, persisted config files that store LogStyle as a number, or copy-paste from outdated docs.
Related errors
AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09).
Data as JSON: /api/errors/a33b60eb04fbc2de.
Report an issue: GitHub.