{"id":"536769ac201eaf49","repo":"evanw/esbuild","slug":"missing-kind-in-callname-call","errorCode":null,"errorMessage":"Missing \"kind\" in ${callName}() call","messagePattern":"Missing \"kind\" in (.+?)\\(\\) call","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":795,"sourceCode":"          callback(failureErrorWithLog('Transform failed', [error], []), null)\n        })\n      }\n    }\n    if ((typeof input === 'string' || input instanceof Uint8Array) && input.length > 1024 * 1024) {\n      let next = start\n      start = () => fs.writeFile(input, next)\n    }\n    start(null)\n  }\n\n  let formatMessages: StreamService['formatMessages'] = ({ callName, refs, messages, options, callback }) => {\n    if (!options) throw new Error(`Missing second argument in ${callName}() call`)\n    let keys: OptionKeys = {}\n    let kind = getFlag(options, keys, 'kind', mustBeString)\n    let color = getFlag(options, keys, 'color', mustBeBoolean)\n    let terminalWidth = getFlag(options, keys, 'terminalWidth', mustBeInteger)\n    checkForInvalidFlags(options, keys, `in ${callName}() call`)\n    if (kind === void 0) throw new Error(`Missing \"kind\" in ${callName}() call`)\n    if (kind !== 'error' && kind !== 'warning') throw new Error(`Expected \"kind\" to be \"error\" or \"warning\" in ${callName}() call`)\n    let request: protocol.FormatMsgsRequest = {\n      command: 'format-msgs',\n      messages: sanitizeMessages(messages, 'messages', null, '', terminalWidth),\n      isWarning: kind === 'warning',\n    }\n    if (color !== void 0) request.color = color\n    if (terminalWidth !== void 0) request.terminalWidth = terminalWidth\n    sendRequest<protocol.FormatMsgsRequest, protocol.FormatMsgsResponse>(refs, request, (error, response) => {\n      if (error) return callback(new Error(error), null)\n      callback(null, response!.messages)\n    })\n  }\n\n  let analyzeMetafile: StreamService['analyzeMetafile'] = ({ callName, refs, metafile, options, callback }) => {\n    if (options === void 0) options = {}\n    let keys: OptionKeys = {}\n    let color = getFlag(options, keys, 'color', mustBeBoolean)","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/lib/shared/common.ts#L777-L813","documentation":"esbuild's formatMessages() requires an options object whose 'kind' field tells esbuild whether to format the messages as errors or as warnings (the formatting differs in severity prefix). The check at lib/shared/common.ts:795 fires when 'kind' is undefined after getFlag() extracts it, meaning the caller passed an options object but omitted the mandatory field. esbuild refuses to guess because error vs. warning formatting is semantically meaningful for terminal output and CI exit codes.","triggerScenarios":"Calling esbuild.formatMessages(messages, {}) with no 'kind'. Calling it with options that set color or terminalWidth but forget kind. Passing options whose kind is not a string (getFlag returns undefined for non-strings via mustBeString), e.g. kind: 1 or kind: null.","commonSituations":"Devs copy the analyzeMetafile() signature (where options and most fields are optional) onto formatMessages(). IDE autocomplete suggests 'color' and 'terminalWidth' first; devs submit early. Migration from an older API that defaulted kind. Generating the options object dynamically from a config map that doesn't include 'kind'.","solutions":["Pass options: { kind: 'error' } or { kind: 'warning' } as the second argument to formatMessages().","If you built the options object programmatically, assert the 'kind' key is present before calling.","Upgrade @types/esbuild / esbuild to a version matching the runtime so the TS signature (kind: 'error' | 'warning', required) is enforced at compile time."],"exampleFix":"// before\nawait esbuild.formatMessages(msgs, { color: true });\n// after\nawait esbuild.formatMessages(msgs, { kind: 'error', color: true });","handlingStrategy":"validation","validationCode":"import type { FormatMessagesOptions } from 'esbuild';\n\nfunction safeFormat(messages, opts) {\n  if (!opts || (opts.kind !== 'error' && opts.kind !== 'warning')) {\n    throw new TypeError(\"formatMessages requires options.kind = 'error' | 'warning'\");\n  }\n  return esbuild.formatMessages(messages, opts);\n}","typeGuard":"function isFormatKind(v): v is 'error' | 'warning' {\n  return v === 'error' || v === 'warning';\n}","tryCatchPattern":null,"preventionTips":["Treat the second argument to formatMessages as a required, fully-typed object; do not pass partial config.","Lock the TS types from the installed esbuild version so the compiler enforces kind.","Wrap formatMessages in a project helper that validates kind once."],"tags":["api-misuse","formatmessages","validation"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}