{"record":{"id":"2ee7e635b10b692c","repo":"karatelabs/karate","slug":"invalid-sitename","errorCode":null,"errorMessage":"invalid ${siteName}","messagePattern":"invalid (.+?)","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1694,"sourceCode":"        if (n == null) {\n            // Defensive — empty LHS only happens in error-recovery edge cases.\n            return;\n        }\n        // Top-level Object/Array literal refines into a destructuring pattern.\n        if (n.type == NodeType.LIT_EXPR && n.size() >= 1) {\n            NodeType lit = n.getFirst().type;\n            if (lit == NodeType.LIT_ARRAY || lit == NodeType.LIT_OBJECT) {\n                return;\n            }\n        }\n        // Peel any layers of parens. Per spec, a ParenthesizedExpression around an\n        // ObjectLiteral or ArrayLiteral does NOT refine to a destructuring pattern,\n        // so it becomes invalid; everything else falls through to the simple check.\n        while (n.type == NodeType.PAREN_EXPR) {\n            // PAREN_EXPR shape: [(, body, )]\n            Node body = n.size() >= 2 ? n.get(1) : null;\n            if (body == null) {\n                throw new ParserException(\"invalid \" + siteName);\n            }\n            if (body.type == NodeType.EXPR_LIST && body.size() != 1) {\n                throw new ParserException(\"invalid \" + siteName + \": comma expression\");\n            }\n            Node inner = stripExprWrappers(body);\n            if (inner == null) {\n                throw new ParserException(\"invalid \" + siteName);\n            }\n            if (inner.type == NodeType.LIT_EXPR && inner.size() >= 1) {\n                NodeType lit = inner.getFirst().type;\n                if (lit == NodeType.LIT_ARRAY || lit == NodeType.LIT_OBJECT) {\n                    throw new ParserException(\"invalid \" + siteName + \": parenthesized destructuring pattern\");\n                }\n            }\n            n = inner;\n        }\n        switch (n.type) {\n            case REF_EXPR -> {","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1676-L1712","documentation":"A generic invalidity error emitted during Karate's destructuring-target validation, with `${siteName}` substituted (e.g. 'invalid assignment target' or a declaration site name). While unwrapping parentheses around a would-be destructuring/assignment target, the parser found a PAREN_EXPR node with no body — a malformed parenthesized expression — so the target cannot be valid. Parsing aborts.","triggerScenarios":"Parsing a syntactically broken parenthesized expression used as a destructuring or assignment target, e.g. `() = 5;` or `var () = arr;` — the PAREN_EXPR shape check `n.size() >= 2 ? n.get(1) : null` yields null and throws 'invalid ' + siteName.","commonSituations":"Typos leaving an empty `()` where a binding was expected; incomplete edits saving partially written destructuring code; macro/template generation producing malformed targets.","solutions":["Complete the expression inside the parentheses with a valid binding or target","Remove the empty parentheses if they are leftover syntax","Re-check the statement for missing identifiers on the left side of `=` or in a declaration list"],"exampleFix":"// before\nvar () = arr; // empty target\n// after\nvar [a, b] = arr;","handlingStrategy":"validation","validationCode":"// detect empty parentheses in binding/assignment position\nif (/\\b(?:var|let|const)\\s*\\(\\s*\\)/.test(src) || /^\\(\\s*\\)\\s*=[^=]/.test(src.trim())) {\n  throw new Error('empty () used as a destructuring/assignment target');\n}","typeGuard":null,"tryCatchPattern":"try {\n  runScript(src);\n} catch (e) {\n  if (/^invalid /.test(e.message)) {\n    // inspect the left-hand side for malformed parens\n  }\n  throw e;\n}","preventionTips":["Never leave empty parens where a binding belongs","Check generated code templates for incomplete identifiers","Format/lint code before executing in Karate"],"tags":["javascript","parser","syntax","destructuring"],"backgroundTag":"invalid-argument-format","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"}