{"record":{"id":"33988f89e9a6aecb","repo":"karatelabs/karate","slug":"missing-argument-index","errorCode":null,"errorMessage":"missing argument {index}","messagePattern":"missing argument (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/Args.java","lineNumber":95,"sourceCode":"        final Class<T> type;\n        final T defaultValue;\n        final boolean optional;\n\n        Arg(Class<T> type, T defaultValue, boolean optional) {\n            this.type = type;\n            this.defaultValue = defaultValue;\n            this.optional = optional;\n        }\n\n        public Arg<T> optional(T defaultValue) {\n            return new Arg<>(type, defaultValue, true);\n        }\n\n        @SuppressWarnings(\"unchecked\")\n        T extract(Object[] args, int index) {\n            if (index >= args.length) {\n                if (optional) return defaultValue;\n                throw new IllegalArgumentException(\"missing argument \" + index);\n            }\n            Object raw = args[index];\n            if (type == String.class) return (T) raw.toString();\n            if (type == Integer.class) return (T) Integer.valueOf(((Number) raw).intValue());\n            if (type == Double.class) return (T) Double.valueOf(((Number) raw).doubleValue());\n            return type.cast(raw);\n        }\n    }\n\n}\n","sourceCodeStart":77,"sourceCodeEnd":106,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/Args.java#L77-L106","documentation":"Args.extract converts a JS call's positional arguments into typed Java parameters; when the argument at the given index is absent and not marked optional, it throws IllegalArgumentException 'missing argument {index}'.","triggerScenarios":"Invoking a registered JS function/method with fewer positional arguments than required — e.g. calling a Karate JS API with omitted required parameters, or spreading an array shorter than the parameter list.","commonSituations":"Calling Karate JS built-ins from a script with arguments accidentally dropped during refactoring; conditionally-built argument arrays that end up too short; documentation examples used with older/newer signatures.","solutions":["Count and supply all required positional arguments at the call site","Check the function's signature/docs for which parameters are optional and which have defaults","If the caller builds an args array dynamically, assert its length before invoking","For optional parameters, pass explicit placeholders (null/undefined) at earlier positions rather than shortening the array"],"exampleFix":"// before (JS)\nkarate.call('delete-user');            // required id arg missing\n// after (JS)\nkarate.call('delete-user', userId);    // supply every required argument","handlingStrategy":"validation","validationCode":"// JS side, before invoking\nif (arguments.length < 2) {\n    throw new Error('expected 2 arguments, got ' + arguments.length);\n}\napiCall(arguments[0], arguments[1]);","typeGuard":null,"tryCatchPattern":"// Java side\ntry {\n    return invoke(args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"missing argument\")) {\n        throw new ScriptCallException(\"call site supplied too few arguments: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Supply all required positional arguments; use explicit null placeholders rather than dropping trailing entries","Re-check call signatures after library upgrades","Avoid building argument arrays conditionally without a length assertion","Name optional parameters in wrapper functions so callers can see arity"],"tags":["javascript","arguments","api-misuse"],"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-19T12:17:13.211Z"}