{"record":{"id":"a3cd13dcf62a7e89","repo":"evanw/esbuild","slug":"missing-second-argument-in-callname-call","errorCode":null,"errorMessage":"Missing second argument in ${callName}() call","messagePattern":"Missing second argument in (.+?)\\(\\) call","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/shared/common.ts","lineNumber":791,"sourceCode":"      } catch (e) {\n        let flags: string[] = []\n        try { pushLogFlags(flags, options, {}, isTTY, transformLogLevelDefault) } catch { }\n        const error = extractErrorMessageV8(e, streamIn, details, void 0, '')\n        sendRequest(refs, { command: 'error', flags, error }, () => {\n          error.detail = details.load(error.detail)\n          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    let logStyle = getFlag(options, keys, 'logStyle', mustBeString)\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    if (logStyle !== void 0) request.logStyle = logStyle\n    sendRequest<protocol.FormatMsgsRequest, protocol.FormatMsgsResponse>(refs, request, (error, response) => {\n      if (error) return callback(new Error(error), null)","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/lib/shared/common.ts#L773-L809","documentation":"formatMessages() requires an options object as its second argument (it must at least contain `kind`). At lib/shared/common.ts:791 esbuild throws if that argument is missing/falsy, before attempting to read any option fields.","triggerScenarios":"Calling `formatMessages(msgs)`, `formatMessages(msgs, null)`, or `formatMessages(msgs, undefined)`.","commonSituations":"Following an older/wrong example; assuming options is optional; destructuring config and passing an undefined variable.","solutions":["Pass a second argument with at least `{ kind: 'error' }` or `{ kind: 'warning' }`.","If you have no other preferences, use formatMessages(msgs, { kind: 'error' })."],"exampleFix":"// before\nconst out = await esbuild.formatMessages(result.warnings)\n\n// after\nconst out = await esbuild.formatMessages(result.warnings, { kind: 'warning' })","handlingStrategy":"validation","validationCode":"function format(msgs, opts) {\n  if (!opts) throw new Error('formatMessages requires an options object with kind')\n  return esbuild.formatMessages(msgs, opts)\n}\nawait format(result.warnings, { kind: 'warning' })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a second argument to formatMessages with at least { kind: ... }.","Wrap formatMessages in your own helper that defaults the options object.","Derive kind from the array you pass: 'error' for errors, 'warning' for warnings."],"tags":["api","validation","format-messages"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}