{"id":"9447be79373e6a13","repo":"evanw/esbuild","slug":"invalid-charset","errorCode":null,"errorMessage":"Invalid charset","messagePattern":"Invalid charset","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":215,"sourceCode":"\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 validateASCIIOnly(value Charset) bool {\n\tswitch value {\n\tcase CharsetDefault, CharsetASCII:\n\t\treturn true\n\tcase CharsetUTF8:\n\t\treturn false\n\tdefault:\n\t\tpanic(\"Invalid charset\")\n\t}\n}\n\nfunc validateExternalPackages(value Packages) bool {\n\tswitch value {\n\tcase PackagesDefault, PackagesBundle:\n\t\treturn false\n\tcase PackagesExternal:\n\t\treturn true\n\tdefault:\n\t\tpanic(\"Invalid packages\")\n\t}\n}\n\nfunc validateTreeShaking(value TreeShaking, bundle bool, format Format) bool {\n\tswitch value {\n\tcase TreeShakingDefault:\n\t\t// If we're in an IIFE then there's no way to concatenate additional code","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L197-L233","documentation":"A panic raised by validateASCIIOnly when the Charset value is not CharsetDefault, CharsetASCII, or CharsetUTF8. Internal invariant reachable only through Go-API misuse (out-of-range Charset).","triggerScenarios":"Go API: BuildOptions.Charset = Charset(7). The JS API's Charset union ('ascii' | 'utf8') maps to valid constants and cannot trigger this.","commonSituations":"Reflective config decoding; fork ordinal drift; unsafe casts.","solutions":["Use only CharsetDefault, CharsetASCII, or CharsetUTF8.","Validate deserialized values against an allowlist.","Do not cast integers to Charset.","Pin a single esbuild version."],"exampleFix":"// before\nopts.Charset = api.Charset(7)\n\n// after\nopts.Charset = api.CharsetUTF8","handlingStrategy":"type-guard","validationCode":"func validCharset(c api.Charset) bool {\n  switch c {\n  case api.CharsetDefault, api.CharsetASCII, api.CharsetUTF8:\n    return true\n  }\n  return false\n}","typeGuard":"type Charset = 'ascii' | 'utf8'\nfunction isCharset(v: unknown): v is Charset {\n  return v === 'ascii' || v === 'utf8'\n}","tryCatchPattern":null,"preventionTips":["Use CharsetASCII or CharsetUTF8 only.","Validate deserialized config values.","Do not cast integers to Charset."],"tags":["api","charset","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}