{"id":"edafada400bfbf4b","repo":"evanw/esbuild","slug":"invalid-format","errorCode":null,"errorMessage":"Invalid format","messagePattern":"Invalid format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":132,"sourceCode":"\tcase PlatformNeutral:\n\t\treturn config.PlatformNeutral\n\tdefault:\n\t\tpanic(\"Invalid platform\")\n\t}\n}\n\nfunc validateFormat(value Format) config.Format {\n\tswitch value {\n\tcase FormatDefault:\n\t\treturn config.FormatPreserve\n\tcase FormatIIFE:\n\t\treturn config.FormatIIFE\n\tcase FormatCommonJS:\n\t\treturn config.FormatCommonJS\n\tcase FormatESModule:\n\t\treturn config.FormatESModule\n\tdefault:\n\t\tpanic(\"Invalid format\")\n\t}\n}\n\nfunc validateSourceMap(value SourceMap) config.SourceMap {\n\tswitch value {\n\tcase SourceMapNone:\n\t\treturn config.SourceMapNone\n\tcase SourceMapLinked:\n\t\treturn config.SourceMapLinkedWithComment\n\tcase SourceMapInline:\n\t\treturn config.SourceMapInline\n\tcase SourceMapExternal:\n\t\treturn config.SourceMapExternalWithoutComment\n\tcase SourceMapInlineAndExternal:\n\t\treturn config.SourceMapInlineAndExternal\n\tdefault:\n\t\tpanic(\"Invalid source map\")\n\t}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L114-L150","documentation":"A panic raised by validateFormat when the Format value is not one of FormatDefault, FormatIIFE, FormatCommonJS, FormatESModule. As with the other validate* panics, the typed public API should prevent this; reaching it means an out-of-range Format was constructed, typically via unsafe Go code.","triggerScenarios":"Go API: set BuildOptions.Format = Format(42) or any value produced by an unchecked cast. The JS API constrains Format to 'iife' | 'cjs' | 'esm' and cannot trigger this. Fires during option validation at build start.","commonSituations":"Reading the format from an untyped config map and casting with Format(intVal) without validation; ABI mismatch between a vendored esbuild fork and the public enum; fuzzing or property-based tests that synthesize random enum values.","solutions":["Use only the documented Format constants (FormatIIFE, FormatCommonJS, FormatESModule, FormatDefault).","Validate decoded values against an allowlist before assignment.","Avoid casting arbitrary integers to Format.","Re-vendor the latest esbuild Go package if you suspect an ABI drift."],"exampleFix":"// before\nopts.Format = api.Format(rawValue)  // rawValue out of range\n\n// after\nswitch rawValue {\ncase \"iife\": opts.Format = api.FormatIIFE\ncase \"cjs\":  opts.Format = api.FormatCommonJS\ncase \"esm\": opts.Format = api.FormatESModule\n}","handlingStrategy":"type-guard","validationCode":"func validFormat(f api.Format) bool {\n  switch f {\n  case api.FormatDefault, api.FormatIIFE, api.FormatCommonJS, api.FormatESModule:\n    return true\n  }\n  return false\n}","typeGuard":"type Format = 'iife' | 'cjs' | 'esm'\nfunction isFormat(v: unknown): v is Format {\n  return v === 'iife' || v === 'cjs' || v === 'esm'\n}","tryCatchPattern":null,"preventionTips":["Use the documented Format constants only.","Validate deserialized values through a guarded switch.","Do not cast integers to Format."],"tags":["api","format","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}