{"id":"65cd442765235bdf","repo":"evanw/esbuild","slug":"invalid-source-map","errorCode":null,"errorMessage":"Invalid source map","messagePattern":"Invalid source map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":149,"sourceCode":"\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}\n}\n\nfunc validateLegalComments(value LegalComments, bundle bool) config.LegalComments {\n\tswitch value {\n\tcase LegalCommentsDefault:\n\t\tif bundle {\n\t\t\treturn config.LegalCommentsEndOfFile\n\t\t} else {\n\t\t\treturn config.LegalCommentsInline\n\t\t}\n\tcase LegalCommentsNone:\n\t\treturn config.LegalCommentsNone\n\tcase LegalCommentsInline:\n\t\treturn config.LegalCommentsInline\n\tcase LegalCommentsEndOfFile:\n\t\treturn config.LegalCommentsEndOfFile\n\tcase LegalCommentsLinked:","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L131-L167","documentation":"A panic raised by validateSourceMap when the SourceMap value is not one of the documented constants (SourceMapNone, SourceMapLinked, SourceMapInline, SourceMapExternal, SourceMapInlineAndExternal). The typed JS/TS API makes this unreachable; only Go-API misuse (out-of-range SourceMap) hits it.","triggerScenarios":"Go API: assign BuildOptions.Sourcemap = SourceMap(7). The JS API's Sourcemap option is a closed union ('true' | 'false' | 'inline' | 'linked' | 'external' | 'both') that maps to valid constants and cannot reach this panic.","commonSituations":"Config decoded from JSON into a raw int then cast; a fork that renamed/removed a SourceMap variant while the caller still references the old ordinal; unsafe pointer tricks over the struct field.","solutions":["Use only the documented SourceMap constants.","Map user-facing strings to constants through a guarded switch.","Never cast an unchecked integer to SourceMap.","Add a regression test enumerating every supported sourcemap mode."],"exampleFix":"// before\nopts.Sourcemap = api.SourceMap(7)\n\n// after\nopts.Sourcemap = api.SourceMapLinked  // or Inline/External/Both/None","handlingStrategy":"type-guard","validationCode":"func validSourceMap(s api.SourceMap) bool {\n  switch s {\n  case api.SourceMapNone, api.SourceMapLinked, api.SourceMapInline, api.SourceMapExternal, api.SourceMapInlineAndExternal:\n    return true\n  }\n  return false\n}","typeGuard":"type SourceMap = true | false | 'inline' | 'linked' | 'external' | 'both'\nfunction isSourceMap(v: unknown): v is SourceMap {\n  return [true, false, 'inline', 'linked', 'external', 'both'].includes(v as any)\n}","tryCatchPattern":null,"preventionTips":["Use documented SourceMap constants only.","Validate external config values against the union.","Pin a single esbuild version."],"tags":["api","sourcemap","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}