{"record":{"id":"33b78bdfdda5da77","repo":"karatelabs/karate","slug":"get-needs-at-least-one-argument","errorCode":null,"errorMessage":"get() needs at least one argument","messagePattern":"get\\(\\) needs at least one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":510,"sourceCode":"    private JavaInvokable readAsBytes() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"readAsBytes() needs at least one argument\");\n            }\n            String path = args[0] + \"\";\n            Resource resource = getCurrentResource().resolve(path);\n            try (java.io.InputStream is = resource.getStream()) {\n                return is.readAllBytes();\n            } catch (java.io.IOException e) {\n                throw new RuntimeException(\"Failed to read bytes from: \" + path, e);\n            }\n        };\n    }\n\n    private JavaInvokable get() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"get() needs at least one argument\");\n            }\n            String expr = args[0] + \"\";\n\n            Object result;\n            // a $-prefix always means a path expression, never a variable name - isSimpleIdentifier\n            // accepts '$' as a leading char, so without this `karate.get('$x')` would hunt for a\n            // variable literally called \"$x\" instead of resolving the bare `$varname` form\n            if (!expr.startsWith(\"$\") && isSimpleIdentifier(expr)) {\n                result = engine.get(expr);\n            } else {\n                // Anything else - a $-prefixed JsonPath, an XPath, `get[N] foo[*].a`, or a\n                // plain dot / bracket chain like 'foo.bar.baz' - goes to the same evaluator\n                // the Gherkin RHS uses, which is what v1 did (karate.get delegated straight\n                // to evalKarateExpression). The hand-rolled JsonPath split that used to live\n                // here understood none of the other forms, and handed jayway the raw target\n                // so an XML or JSON-string variable silently answered nothing.\n                ScenarioRuntime rt = ScenarioRuntime.currentOrNull();\n                if (rt == null) {","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L492-L528","documentation":"Guard clause inside the karate.get() JS binding: it requires at least one argument (the key/name to look up), but was called with none. Fires when a script calls karate.get() without arguments; pass the variable or config key to retrieve.","triggerScenarios":"karate.get() with no arguments; building the expression dynamically (e.g. karate.get(exprVar)) where exprVar is undefined so the call has no args.","commonSituations":"Extracting nested values with karate.get('$.path.to.value') and accidentally deleting the string; refactoring variable names so the argument disappears.","solutions":["Pass the expression: karate.get('myVar') or karate.get('$.obj.nested').","Remember $-prefixed strings are always JSON-path expressions, not variable names.","Ensure the expression variable is defined before the call."],"exampleFix":"// before\nvar val = karate.get();\n// after\nvar val = karate.get('$.user.address.city');","handlingStrategy":"validation","validationCode":"if (!expr) throw new Error('karate.get requires an expression');\nvar v = karate.get(expr);","typeGuard":"function validGetArg(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"var v;\ntry { v = karate.get(expr); }\ncatch (e) { if ((e.message || '').indexOf('get() needs at least one argument') >= 0) karate.fail('karate.get called without an expression'); throw e; }","preventionTips":["Always pass a quoted variable name or $-prefixed JSON path.","Remember $-prefixed strings are path expressions, not variable names.","Avoid building the argument from variables that may be undefined."],"tags":["javascript","json-path","argument-validation"],"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"}