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 false

View on GitHub (pinned to f6058f8364)

Solutions

  1. Use api.LogStyleDefault (zero value) or api.LogStyleClang / api.LogStyleVisualStudio.
  2. Bounds-check any integer destined for LogStyle against 0..2.
  3. Store the preference as a string and map to the constant at load.
  4. 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

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.