{"record":{"id":"25aa397f4e287c9c","repo":"karatelabs/karate","slug":"continue-references-an-undefined-label-target","errorCode":null,"errorMessage":"continue references an undefined label: ${target}","messagePattern":"continue references an undefined label: (.+?)","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":422,"sourceCode":"                }\n                return new Label(name, labelsIterationStatement(node), labels);\n            }\n            // §15.7.1 makes a static initialization block a boundary of the same kind\n            // as a function body: nothing inside it may name a label outside it.\n            case FN_EXPR, FN_ARROW_EXPR, CLASS_STATIC_BLOCK -> {\n                return null;\n            }\n            case BREAK_STMT -> {\n                String target = labelReference(node);\n                if (target != null && !Label.contains(labels, target, false)) {\n                    throw new ParserException(\"break references an undefined label: \" + target);\n                }\n            }\n            case CONTINUE_STMT -> {\n                String target = labelReference(node);\n                if (target != null) {\n                    if (!Label.contains(labels, target, false)) {\n                        throw new ParserException(\"continue references an undefined label: \" + target);\n                    }\n                    if (!Label.contains(labels, target, true)) {\n                        throw new ParserException(\"continue label does not name a loop: \" + target);\n                    }\n                }\n            }\n            default -> {\n            }\n        }\n        return labels;\n    }\n\n    /** The label named by a {@code break} / {@code continue}, or null when it has none —\n     *  children are [keyword] or [keyword, label]. */\n    private static String labelReference(Node node) {\n        return node.size() > 1 ? node.get(1).getText() : null;\n    }\n","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L404-L440","documentation":"`continue someLabel;` must reference a label that exists in the current scope. As with break, the parser validates CONTINUE_STMT label references against the Label chain and throws when the target is absent (including targets hidden behind a function/arrow/static-block boundary).","triggerScenarios":"`continue loopLabel;` where loopLabel is undeclared, misspelled, or declared outside the current function body; the check `!Label.contains(labels, target, false)` fails before the loop-kind check runs.","commonSituations":"Refactoring loops into helper functions while keeping labeled continues; typos in label names; removing the labeled loop that a nested continue targeted.","solutions":["Correct the label name to an in-scope labeled iteration statement","Replace `continue label;` with plain `continue;` if the innermost loop is the target","Move the continue back into the same function as the labeled loop, or return a flag from the helper and continue at the call site"],"exampleFix":"// before\narr.forEach(x => { continue loop; }); // label not visible\n// after\nfor (const x of arr) { if (bad(x)) continue loop; }","handlingStrategy":"validation","validationCode":"// Check every `continue X` has a visible label X:\nconst targets = [...src.matchAll(/continue\\s+([A-Za-z_$][\\w$]*)/g)].map(m=>m[1]);\nconst declared = new Set([...src.matchAll(/([A-Za-z_$][\\w$]*):/g)].map(m=>m[1]));\nconst missing = targets.filter(t => !declared.has(t));","typeGuard":null,"tryCatchPattern":"try { eval(js); } catch (e) { if (String(e).includes('continue references an undefined label')) { /* fix or drop the label target */ } throw e; }","preventionTips":["Validate labeled continues when refactoring loops into callbacks","Keep continue statements inside the same function as the labeled loop","Use descriptive, unique loop label names"],"tags":["javascript","parser","labels","continue"],"backgroundTag":"undefined-label-reference","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"}