{"record":{"id":"72238b8773788497","repo":"karatelabs/karate","slug":"no-step-parsed","errorCode":null,"errorMessage":"no step parsed","messagePattern":"no step parsed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":1512,"sourceCode":"        long startTime = System.currentTimeMillis();\n        String trimmed = text == null ? \"\" : text.trim();\n        boolean hasPrefix = false;\n        for (String prefix : Step.PREFIXES) {\n            if (trimmed.startsWith(prefix)) {\n                hasPrefix = true;\n                break;\n            }\n        }\n        if (!hasPrefix) {\n            trimmed = \"* \" + trimmed;\n        }\n        Step parsed;\n        Scenario synthScenario;\n        try {\n            Resource resource = Resource.text(\"Feature:\\nScenario:\\n\" + trimmed);\n            Feature feature = Feature.read(resource);\n            if (feature.getSections().isEmpty()) {\n                throw new RuntimeException(\"no step parsed\");\n            }\n            synthScenario = feature.getSection(0).getScenario();\n            if (synthScenario == null || synthScenario.getSteps() == null || synthScenario.getSteps().isEmpty()) {\n                throw new RuntimeException(\"no step parsed\");\n            }\n            parsed = synthScenario.getSteps().get(0);\n        } catch (Exception e) {\n            Step fakeStep = new Step(scenario, -1);\n            return StepResult.failed(fakeStep, startTime, 0, e);\n        }\n        Step fakeStep = new Step(synthScenario, -1);\n        fakeStep.setLine(parsed.getLine());\n        fakeStep.setEndLine(parsed.getEndLine());\n        fakeStep.setPrefix(parsed.getPrefix());\n        fakeStep.setKeyword(parsed.getKeyword());\n        fakeStep.setText(parsed.getText());\n        fakeStep.setDocString(parsed.getDocString());\n        fakeStep.setDocStringLine(parsed.getDocStringLine());","sourceCodeStart":1494,"sourceCodeEnd":1530,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L1494-L1530","documentation":"ScenarioRuntime parses a raw text snippet by wrapping it in a synthetic feature (`Feature:\\nScenario:\\n` + text). If the Gherkin parser yields no sections at all, the runtime throws \"no step parsed\" because nothing usable was provided.","triggerScenarios":"Calling the API that evaluates a step/feature text with an empty or whitespace-stripped `trimmed` string, or text containing only comments/tags such that Feature.read returns zero sections.","commonSituations":"Passing an empty string variable to dynamic step evaluation; reading step text from an external source (file, env var, DB) that came back blank; building Gherkin programmatically and emitting only `Background:` or comments.","solutions":["Log the exact `trimmed` string before invoking the runtime and ensure it is a non-empty step line like `* print 'hello'`","Trim away Gherkin comments and tags so at least one real step remains","Guard upstream: only call the eval API when the input passes a non-blank, non-comment check"],"exampleFix":"// before\nruntime.evalText(optionalStepText);\n// after\nString t = optionalStepText == null ? \"\" : optionalStepText.strip();\nif (t.isEmpty() || t.startsWith(\"#\") || t.startsWith(\"@\")) {\n    throw new IllegalArgumentException(\"step text required\");\n}\nruntime.evalText(t);","handlingStrategy":"validation","validationCode":"String t = stepText == null ? \"\" : stepText.strip();\nif (t.isEmpty() || t.lines().allMatch(l -> l.strip().isEmpty() || l.strip().startsWith(\"#\") || l.strip().startsWith(\"@\"))) {\n    throw new IllegalArgumentException(\"step text must contain at least one step\");\n}","typeGuard":"static boolean hasParseableStep(String s) {\n    return s != null && s.lines().anyMatch(l -> {\n        String t = l.strip();\n        return !t.isEmpty() && !t.startsWith(\"#\") && (t.startsWith(\"*\") || t.matches(\"(Given|When|Then|And|But)\\\\b.*\"));\n    });\n}","tryCatchPattern":"try { runtime.evalText(text); } catch (RuntimeException e) { if (e.getMessage().equals(\"no step parsed\")) { throw new IllegalArgumentException(\"empty or non-step input: \" + text); } throw e; }","preventionTips":["Validate step text is non-blank before dynamic evaluation","Strip comments/tags from programmatically built Gherkin","Log the exact input string when evaluation fails"],"tags":["gherkin","parsing","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}