{"record":{"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":228,"sourceCode":"\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 {\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":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L210-L246","documentation":"validateASCIIOnly (pkg/api/api_impl.go:228) panics when Charset is not CharsetDefault(0), CharsetASCII(1), or CharsetUTF8(2). The function returns a bool (ASCII-only emission) used by the linker; an unknown value has no defined escaping behavior, so esbuild aborts. Reached from validateBuildOptions.","triggerScenarios":"Passing BuildOptions.Charset (or TransformOptions.Charset) as a raw integer or a deserialized `uint8`. Panic occurs in the option-validation pass before scanning.","commonSituations":"Config UIs that store charset as a small int, version drift between a wrapper and the core (e.g. a renamed CharsetASCII8 constant), or a typo like `Charset: api.CharsetLatin1` (no such constant).","solutions":["Use api.CharsetDefault (or leave unset) for ASCII-safe output, api.CharsetASCII, or api.CharsetUTF8.","Validate decoded integers against 0..2 before casting to Charset.","Serialize the setting as a string (\"default\"/\"ascii\"/\"utf8\") and map at load.","Re-vendor all consumers against a single esbuild version."],"exampleFix":"// before\nopts := api.BuildOptions{Charset: api.Charset(4)}\n\n// after\nopts := api.BuildOptions{Charset: api.CharsetUTF8}","handlingStrategy":"validation","validationCode":"func checkCharset(c api.Charset) error {\n    switch c {\n    case api.CharsetDefault, api.CharsetASCII, api.CharsetUTF8:\n        return nil\n    }\n    return fmt.Errorf(\"invalid charset %d (want 0..2)\", uint8(c))\n}","typeGuard":"func isValidCharset(c api.Charset) bool {\n    switch c {\n    case api.CharsetDefault, api.CharsetASCII, api.CharsetUTF8:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Default to CharsetDefault (ASCII-safe) to maximize output portability.","Avoid storing Charset as a number in user configs; use a string.","Bounds-check decoded integers to 0..2.","Rebuild any generated code after re-vendoring esbuild."],"tags":["esbuild","config","validation","panic","charset","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}