{"record":{"id":"3cabbe64835c1b97","repo":"karatelabs/karate","slug":"fork-argument-must-be-string-array-or-object","errorCode":null,"errorMessage":"fork() argument must be string, array, or object","messagePattern":"fork\\(\\) argument must be string, array, or object","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":901,"sourceCode":"                // Extract errorListener function (receives line string directly)\n                Object errorListenerObj = options.get(\"errorListener\");\n                if (errorListenerObj instanceof JavaCallable jsErrorListener) {\n                    errorListener = line -> {\n                        try {\n                            jsErrorListener.call(null, line);\n                        } catch (Exception e) {\n                            logger.warn(\"process errorListener error: {}\", e.getMessage());\n                        }\n                    };\n                }\n\n                // Check start option (default true)\n                Object startObj = options.get(\"start\");\n                if (startObj instanceof Boolean) {\n                    autoStart = (Boolean) startObj;\n                }\n            } else {\n                throw new RuntimeException(\"fork() argument must be string, array, or object\");\n            }\n\n            if (listener != null) {\n                builder.listener(listener);\n            }\n            if (errorListener != null) {\n                builder.errorListener(errorListener);\n            }\n\n            ProcessHandle handle = ProcessHandle.create(builder.build());\n\n            // Wire signal consumer for listen/listenResult integration\n            ScenarioRuntime rt = getRuntime();\n            if (rt != null) {\n                handle.setSignalConsumer(rt::setListenResult);\n            }\n\n            if (autoStart) {","sourceCodeStart":883,"sourceCodeEnd":919,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L883-L919","documentation":"`karate.fork()` accepts a string command, an array of args, or a config Map (with options like `args`, `start`, listeners). After parsing optional Map options, the library throws this when the first argument was none of the supported types — meaning it reached the else branch of the type dispatch.","triggerScenarios":"karate.fork(<nonStringListMap>) — e.g. karate.fork(42), karate.fork(true), karate.fork(null), or a Map that was already consumed by the options branch pattern mismatch (a value typed as Number/Boolean instead of the expected types).","commonSituations":"Passing a port number instead of the command string; passing the result of an expression that returned a Boolean/Number; JSON parsed value that is a primitive rather than the expected array/object; migrating from another API where fork took a number (like a pid).","solutions":["Pass a string: karate.fork('mvn spring-boot:run')","Pass an array: karate.fork(['java', '-jar', 'app.jar'])","Pass an options Map containing args: karate.fork({ args: ['java', '-jar', 'app.jar'], start: true })","Stringify or restructure the argument before the call; verify its type with karate.type(value)"],"exampleFix":"// before\nkarate.fork(8080) // unsupported type\n// after\nkarate.fork({ args: ['serve', '-p', '8080'] })","handlingStrategy":"type-guard","validationCode":"// JS\nfunction isForkArg(v) { return typeof v === 'string' || Array.isArray(v) || (v !== null && typeof v === 'object'); }\nif (!isForkArg(arg)) throw new Error('fork arg must be string/array/object, got: ' + typeof arg);","typeGuard":"function isForkArg(v) { return typeof v === 'string' || Array.isArray(v) || (v !== null && typeof v === 'object'); }","tryCatchPattern":"try { karate.fork(arg); } catch (e) { if (('' + e).indexOf('fork() argument must be') !== -1) { karate.log('unsupported fork arg: ' + arg); } throw e; }","preventionTips":["Wrap commands in string, array, or { args: [...] } map","Do not pass pids/ports/booleans to fork()","Use karate.type(arg) to sanity-check before calling"],"tags":["javascript","process-execution","argument-type"],"backgroundTag":"invalid-argument-value","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"}