{"record":{"id":"7e8b0095d68e84ec","repo":"karatelabs/karate","slug":"sysprop-needs-the-property-name","errorCode":null,"errorMessage":"sysprop() needs the property name","messagePattern":"sysprop\\(\\) needs the property name","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":482,"sourceCode":"            }\n            Object fallback = args.length > 1 ? args[1] : null;\n            Object first = args[0];\n            if (first == null) return fallback;\n            String value = System.getenv(first.toString());\n            return (value == null || value.isEmpty()) ? fallback : value;\n        };\n    }\n\n    /**\n     * {@code karate.sysprop('NAME')} / {@code karate.sysprop('NAME', 'default')} —\n     * read a JVM system property. Cleaner alternative to\n     * {@code karate.properties['NAME']} with first-class default support; reads\n     * from the same merged map (CLI {@code -D}, Maven/Gradle, and {@code Runner.Builder.systemProperties}).\n     */\n    private JavaInvokable sysprop() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"sysprop() needs the property name\");\n            }\n            Object fallback = args.length > 1 ? args[1] : null;\n            Object first = args[0];\n            if (first == null) return fallback;\n            String value = getProperty(first.toString());\n            return (value == null || value.isEmpty()) ? fallback : value;\n        };\n    }\n\n    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();","sourceCodeStart":464,"sourceCodeEnd":500,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L464-L500","documentation":"karate.sysprop() reads a JVM system property (from CLI -D, Maven/Gradle, or Runner.Builder.systemProperties) with optional fallback; the property name is required. Karate throws this when the callable receives zero arguments.","triggerScenarios":"Calling karate.sysenv()/sysprop() incorrectly, specifically karate.sysprop() with an empty args list; omitting the name when using the two-argument default form.","commonSituations":"Wiring runner-configurable properties in karate-config.js and dropping the name argument during refactor; copy-paste of sysprop lines where the string literal was deleted.","solutions":["Pass the property name: karate.sysprop('karate.env').","Use karate.sysprop('prop.name', 'fallback') for defaults.","Verify the property name is a non-empty string literal or defined variable."],"exampleFix":"// before\nvar env = karate.sysprop();\n// after\nvar env = karate.sysprop('karate.env', 'dev');","handlingStrategy":"validation","validationCode":"if (!propName) throw new Error('sysprop requires a property name');\nvar v = karate.sysprop(propName, fallback);","typeGuard":"function validSyspropCall(name) { return typeof name === 'string' && name.length > 0; }","tryCatchPattern":"var v;\ntry { v = karate.sysprop(name, 'default'); }\ncatch (e) { if ((e.message || '').indexOf('sysprop() needs') >= 0) v = 'default'; else throw e; }","preventionTips":["Pass the property name as a string literal wherever possible.","Use the two-argument fallback form instead of conditional calls.","Centralize system-property reads in karate-config.js."],"tags":["javascript","system-properties","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"}