{"record":{"id":"1e99192d48a7eefb","repo":"oven-sh/bun","slug":"required-argument-name-cannot-follow-an-optiona","errorCode":null,"errorMessage":"Required argument ${name} cannot follow an optional argument","messagePattern":"Required argument (.+?) cannot follow an optional argument","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/bindgen-lib-internal.ts","lineNumber":843,"sourceCode":"  return func;\n}\n\nfunction validateVariant(variant: any) {\n  let minRequiredArgs = 0;\n  let seenOptionalArgument = false;\n  let i = 0;\n\n  for (const [name, type] of Object.entries(variant.args) as [string, TypeImpl][]) {\n    if (!(type instanceof TypeImpl)) {\n      throw new Error(`Expected type for argument ${name}, got ${inspect(type)}`);\n    }\n    i += 1;\n    if (type.isVirtualArgument()) {\n      continue;\n    }\n    if (!type.flags.optional && !(\"default\" in type.flags)) {\n      if (seenOptionalArgument) {\n        throw new Error(`Required argument ${name} cannot follow an optional argument`);\n      }\n      minRequiredArgs++;\n    } else {\n      seenOptionalArgument = true;\n    }\n  }\n\n  return { minRequiredArgs };\n}\n\nfunction snapshotCallerLocation(): string {\n  const stack = new Error().stack!;\n  const lines = stack.split(\"\\n\");\n  let i = 1;\n  for (; i < lines.length; i++) {\n    if (!lines[i].includes(import.meta.dir)) {\n      return lines[i];\n    }","sourceCodeStart":825,"sourceCodeEnd":861,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/bindgen-lib-internal.ts#L825-L861","documentation":"Thrown by validateVariant in the bindgen code generator when parsing a .bind.ts variant: an argument without `optional` or `default` flags appears after an argument that has one. This ordering cannot be expressed in the generated JavaScript signature (JS positional args cannot be required after an optional slot), so the generator aborts. The input at fault is the args object of the variant being validated.","triggerScenarios":"Thrown at src/codegen/bindgen-lib-internal.ts:843 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reorder the variant's arguments so all required arguments come before optional/defaulted ones","Give the offending required argument a default value or mark it optional","If the argument is synthesized by the generator rather than user-facing, mark it as a virtual argument so the ordering check skips it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","contentChangedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}