{"record":{"id":"cede1fdb75c3560a","repo":"karatelabs/karate","slug":"toabsolutepath-needs-a-path-argument","errorCode":null,"errorMessage":"toAbsolutePath() needs a path argument","messagePattern":"toAbsolutePath\\(\\) needs a path argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":1126,"sourceCode":"                throw new RuntimeException(\"render() read arg should not be null\");\n            } else {\n                readPath = args[0] + \"\";\n            }\n            if (args.length > 1 && args[1] instanceof Map) {\n                vars = (Map<String, Object>) args[1];\n            }\n            return markup().processPath(readPath, vars);\n        };\n    }\n\n    /**\n     * karate.toAbsolutePath(path) - Convert a relative path to absolute.\n     * Resolves relative to the current feature file's directory.\n     */\n    private JavaInvokable toAbsolutePath() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"toAbsolutePath() needs a path argument\");\n            }\n            String path = args[0] + \"\";\n            Resource resource = getCurrentResource().resolve(path);\n            if (resource.isFile() && resource.getPath() != null) {\n                return resource.getPath().toAbsolutePath().toString();\n            }\n            // For classpath resources, return the prefixed path\n            return resource.getPrefixedPath();\n        };\n    }\n\n    /**\n     * karate.write(value, path) - Write content to a file.\n     * Path is relative to the output directory (e.g., target/karate-reports).\n     */\n    private JavaInvokable write() {\n        return args -> {\n            if (args.length < 2) {","sourceCodeStart":1108,"sourceCodeEnd":1144,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L1108-L1144","documentation":"karate.toAbsolutePath(path) converts a relative path to an absolute one, resolved against the current feature file's directory. The library throws this when the function is called with no argument, since there is no path to resolve.","triggerScenarios":"`karate.toAbsolutePath()` with zero arguments in a JS block; calling it before supplying the relative path argument.","commonSituations":"Building the path dynamically and the variable concatenation produced an empty call; misunderstanding the API as taking no args to get the feature directory (use karate.getConstants() or similar instead).","solutions":["Pass the relative path as a string: karate.toAbsolutePath('data/test.json')","If you need the feature directory itself, resolve an empty/'.' path: karate.toAbsolutePath('.')","Verify the argument expression is not accidentally omitted during string building."],"exampleFix":"// before\nvar abs = karate.toAbsolutePath();\n// after\nvar abs = karate.toAbsolutePath('data/test.json');","handlingStrategy":"validation","validationCode":"// JS\nif (relPath == null) karate.fail('toAbsolutePath needs a path');\nvar abs = karate.toAbsolutePath(relPath);","typeGuard":"function isNonEmptyString(s) { return typeof s === 'string' && s.length > 0; }","tryCatchPattern":"try { return karate.toAbsolutePath(p); } catch (e) { karate.warn('toAbsolutePath failed: ' + e); return p; }","preventionTips":["Never call toAbsolutePath with zero args; pass '.' to get the feature directory","Check dynamically built paths before calling","Remember resolution is relative to the feature file's directory"],"tags":["javascript","argument-validation","paths"],"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"}