{"record":{"id":"f21fdaf45bb82cbf","repo":"karatelabs/karate","slug":"duplicate-binding-name-name-is-not-allowed-in-a-catch","errorCode":null,"errorMessage":"duplicate binding name '${name}' is not allowed in a catch parameter","messagePattern":"duplicate binding name '(.+?)' is not allowed in a catch parameter","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1127,"sourceCode":"                }\n                if (ch.token.type == IDENT) {\n                    binding = ch; // simple catch binding — no duplicate possible\n                    break;\n                }\n                // skip the L_PAREN\n            } else {\n                binding = ch; // LIT_ARRAY / LIT_OBJECT pattern\n                break;\n            }\n        }\n        if (binding == null) {\n            return;\n        }\n        List<String> names = new ArrayList<>();\n        collectBoundNames(binding, names);\n        String dup = firstDuplicate(names);\n        if (dup != null) {\n            throw new ParserException(\n                    \"duplicate binding name '\" + dup + \"' is not allowed in a catch parameter\");\n        }\n        if (strict) {\n            for (String name : names) {\n                if (isEvalOrArguments(name)) {\n                    throw new ParserException(\n                            \"'\" + name + \"' is not a valid binding name in strict mode\");\n                }\n            }\n        }\n    }\n\n    /** A strict var/let/const declaration may not bind {@code eval} / {@code arguments}\n     *  — including inside a destructuring pattern. (Lexical duplicate-BoundNames for\n     *  let/const patterns is a distinct rule, deferred — VAR_DECL doesn't carry the\n     *  let-vs-var distinction.) */\n    private static void checkVarDeclName(Node varDecl) {\n        List<String> names = new ArrayList<>();","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1109-L1145","documentation":"A `catch (pattern)` binding may not contain duplicate names. Karate collects every bound name in the catch parameter (including destructured bindings like `catch ({e, e})`) and rejects duplicates, per the ECMAScript CatchParameter uniqueness rule.","triggerScenarios":"Writing `try {} catch (e, ...)` is impossible in JS, but `catch (e) ` duplication arises via destructuring: `catch ({message, message}) {}` or array patterns like `catch ([x, x]) {}` in Karate JS.","commonSituations":"Copy-paste errors in destructured catch clauses; merging bindings from two sources into one pattern without noticing the collision; code-generation templates producing duplicated keys.","solutions":["Remove or rename the duplicated binding in the catch pattern.","If both sources are needed, alias one: `catch ({message: msg1, message: msg2})` — wait, that is still the same key; instead bind once and derive the second value in the body.","If the pattern was accidentally duplicated, simplify to a single binding: `catch (e) { const { message } = e; }`."],"exampleFix":"// before\ntry { risky(); } catch ({ message, message }) { log(message); }\n// after\ntry { risky(); } catch (err) { log(err.message); }","handlingStrategy":"validation","validationCode":"function assertUniqueCatchBinding(catchSrc) {\n  const inner = catchSrc.slice(catchSrc.indexOf('(') + 1, catchSrc.lastIndexOf(')'));\n  const names = inner.match(/[\\w$]+/g) || [];\n  const seen = new Set();\n  for (const n of names) {\n    if (seen.has(n)) throw new Error('duplicate catch binding: ' + n);\n    seen.add(n);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  karate.eval(script);\n} catch (e) {\n  if (String(e.message).includes(\"not allowed in a catch parameter\")) {\n    // simplify the catch pattern to a single binding\n  } else throw e;\n}","preventionTips":["Prefer a single simple catch binding (`catch (err)`) and destructure in the body.","Avoid hand-writing destructured catch patterns; the collision risk outweighs the brevity.","Code generators should deduplicate keys when emitting object patterns."],"tags":["javascript","parser","catch-clause","destructuring"],"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"}