{"record":{"id":"4556bdb5d2c976ed","repo":"karatelabs/karate","slug":"duplicate-parameter-name-name-is-not-allowed-here","errorCode":null,"errorMessage":"duplicate parameter name '${name}' is not allowed here","messagePattern":"duplicate parameter name '(.+?)' is not allowed here","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1062,"sourceCode":"        for (int i = 0, n = args.size(); i < n; i++) {\n            Node arg = args.get(i);\n            if (arg.isToken() || arg.type != NodeType.FN_DECL_ARG) {\n                continue;\n            }\n            collectBindingBoundNames(arg, names);\n        }\n        if (strict) {\n            for (String name : names) {\n                if (isEvalOrArguments(name)) {\n                    throw new ParserException(\n                            \"'\" + name + \"' is not a valid parameter name in strict mode\");\n                }\n            }\n        }\n        if (strict || isArrow || nonSimple) {\n            String dup = firstDuplicate(names);\n            if (dup != null) {\n                throw new ParserException(\n                        \"duplicate parameter name '\" + dup + \"' is not allowed here\");\n            }\n        }\n    }\n\n    /** A FormalParameter is non-simple if it is a destructuring pattern, carries a\n     *  default initializer, or is a rest element — any of which makes the whole\n     *  parameter list non-simple, so duplicate bound names become an early error. */\n    private static boolean isNonSimpleParam(Node arg) {\n        for (int i = 0, n = arg.size(); i < n; i++) {\n            Node ch = arg.get(i);\n            if (ch.isToken()) {\n                if (ch.token.type == EQ || ch.token.type == DOT_DOT_DOT) {\n                    return true;\n                }\n            } else if (ch.type == NodeType.LIT_ARRAY || ch.type == NodeType.LIT_OBJECT) {\n                return true;\n            }","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1044-L1080","documentation":"Duplicate parameter names are allowed only for simple, non-strict functions. Karate's parser rejects duplicates whenever the function is strict, is an arrow function, or has any non-simple parameter (destructuring pattern, default value, rest parameter) — matching the ECMAScript rule that such functions must have unique formal parameter names.","triggerScenarios":"`function f(a, a) {}` combined with strict mode or any destructuring/default/rest param (e.g. `function f({x}, {x}) {}`, `(a, a) => ...`, `function f(a = 1, a) {}`) in Karate JS.","commonSituations":"Old-style code relying on duplicate params where the last wins (`function f(opts, opts)`); adding a default value or destructuring to a legacy function with duplicate names, which suddenly makes duplicates illegal.","solutions":["Rename one of the duplicate parameters and update its uses in the body.","If the last-wins behavior mattered, merge into one parameter or pick defaults: `function f(a, b = a) {}`.","Remove the newly added destructuring/default if it accidentally made a previously tolerated duplicate illegal — but prefer renaming."],"exampleFix":"// before\nfunction configure(opts, opts) { return use(opts); }\n// after\nfunction configure(opts, overrides = opts) { return use({ ...opts, ...overrides }); }","handlingStrategy":"validation","validationCode":"function assertUniqueParams(fnSrc) {\n  const m = fnSrc.match(/\\(([^)]*)\\)/);\n  if (!m) return;\n  const names = m[1].split(',').map(s => s.trim()).filter(Boolean);\n  const seen = new Set();\n  for (const n of names) {\n    const key = n.split(/[=:]/)[0].trim();\n    if (seen.has(key)) throw new Error('duplicate parameter: ' + key);\n    seen.add(key);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  karate.eval(script);\n} catch (e) {\n  if (String(e.message).includes('duplicate parameter name')) {\n    // rename the duplicate in the function signature and body\n  } else throw e;\n}","preventionTips":["Never rely on duplicate-parameter last-wins semantics.","Adding a default/destructuring param makes the whole list 'non-simple' — audit existing duplicates first.","Enable ESLint no-dupe-args on embedded JS sources."],"tags":["javascript","parameters","strict-mode","parser"],"backgroundTag":"invalid-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}