{"record":{"id":"d9d0fb27e2d3ba93","repo":"karatelabs/karate","slug":"karate-callonce-requires-at-least-one-argument-feature-path","errorCode":null,"errorMessage":"karate.callonce() requires at least one argument (feature path)","messagePattern":"karate\\.callonce\\(\\) requires at least one argument \\(feature path\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java","lineNumber":390,"sourceCode":"            if (rt == null) {\n                throw new RuntimeException(\"karate.setupOnce() is not available in this context\");\n            }\n            String name = args.length > 0 && args[0] != null ? args[0].toString() : null;\n            return rt.executeSetupOnce(name);\n        };\n    }\n\n    /**\n     * karate.callonce() - Execute a feature file once per feature and cache the result.\n     */\n    JavaInvokable callonce() {\n        return args -> {\n            ScenarioRuntime rt = getRuntime();\n            if (rt == null) {\n                throw new RuntimeException(\"karate.callonce() is not available in this context\");\n            }\n            if (args.length == 0) {\n                throw new RuntimeException(\"karate.callonce() requires at least one argument (feature path)\");\n            }\n            String path = args[0].toString();\n            Object arg = args.length > 1 ? args[1] : null;\n            return rt.executeJsCallOnce(path, arg);\n        };\n    }\n\n    /**\n     * karate.callSingle() - Execute a feature/JS file once per Suite and cache the result.\n     */\n    JavaInvokable callSingle() {\n        return args -> {\n            ScenarioRuntime rt = getRuntime();\n            if (rt == null) {\n                throw new RuntimeException(\"karate.callSingle() is not available in this context\");\n            }\n            if (args.length == 0) {\n                throw new RuntimeException(\"karate.callSingle() requires at least one argument (path)\");","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsBase.java#L372-L408","documentation":"karate.callonce() requires the path of the feature (or JS file) to call as its first argument. Karate throws this when callonce is invoked with zero arguments, since there is nothing to execute or cache.","triggerScenarios":"`karate.callonce()` with no arguments, or passing only an optional second argument without a path first.","commonSituations":"Refactoring call expressions and dropping the argument; dynamic path variable undefined at call time; copying callonce usage without its feature path.","solutions":["Pass the feature path as the first argument, e.g. karate.callonce('classpath:shared.feature').","If the path comes from a variable, verify it is non-null/non-empty before the call.","If you intended to pass call arguments, supply them as the second argument: karate.callonce(path, arg)."],"exampleFix":"// before\nkarate.callonce();\n\n// after\nkarate.callonce('classpath:shared/data.feature');","handlingStrategy":"validation","validationCode":"if (!path || typeof path !== 'string') { throw new Error('callonce path required'); } karate.callonce(path);","typeGuard":"function isValidPath(p) { return typeof p === 'string' && p.trim().length > 0; }","tryCatchPattern":"try { karate.callonce(path); } catch (e) { if (String(e.message).includes('requires at least one argument')) { karate.log('missing feature path for callonce'); } throw e; }","preventionTips":["Always pass the feature path as the first argument","Assert path variables are non-empty before use","Review call signatures when refactoring call expressions"],"tags":["javascript","arguments","callonce","karate"],"backgroundTag":"missing-required-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"}