{"record":{"id":"fe6b0ee036a067ce","repo":"karatelabs/karate","slug":"render-needs-at-least-one-argument","errorCode":null,"errorMessage":"render() needs at least one argument","messagePattern":"render\\(\\) 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":1100,"sourceCode":"            String path = args[0] + \"\";\n            Resource resource = getCurrentResource().resolve(path);\n            try {\n                return resource.getStream();\n            } catch (Exception e) {\n                throw new RuntimeException(\"Failed to open stream for: \" + path, e);\n            }\n        };\n    }\n\n    /**\n     * karate.render(template) - Render HTML template (similar to doc).\n     * Returns the rendered HTML string without sending to doc consumer.\n     */\n    @SuppressWarnings(\"unchecked\")\n    private JavaInvokable render() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"render() needs at least one argument\");\n            }\n            String readPath;\n            Map<String, Object> vars = null;\n            if (args[0] instanceof Map) {\n                Map<String, Object> map = (Map<String, Object>) args[0];\n                readPath = (String) map.get(\"read\");\n            } else if (args[0] == null) {\n                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","sourceCodeStart":1082,"sourceCodeEnd":1118,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L1082-L1118","documentation":"karate.render() renders a feature/template file to an HTML string in the JS engine. The library throws this when render() is invoked with zero arguments, because it has nothing to render — the read path or template source is mandatory.","triggerScenarios":"Calling karate.render() with no arguments anywhere in a JS block or karate.call-style expression; e.g. `karate.render()` instead of `karate.render('classpath:com/demo/report.feature')` or `karate.render({ read: 'report.feature' })`.","commonSituations":"Copy-pasting a render() snippet and deleting the argument; refactoring code so the path variable became undefined and was dropped; assuming render() without args re-renders the current feature (it does not).","solutions":["Pass the template/feature path as the first argument: karate.render('report.feature')","Pass an options map with a 'read' key: karate.render({ read: 'report.feature', var1: 'x' })","If the path is dynamic, verify the variable is defined before the call and not undefined/null."],"exampleFix":"// before\nvar html = karate.render();\n// after\nvar html = karate.render({ read: 'report.feature' });","handlingStrategy":"validation","validationCode":"// JS\nif (path == null) karate.fail('karate.render() requires a read path');\nvar html = karate.render(path);","typeGuard":"function isRenderableArg(a) { return typeof a === 'string' || (a && typeof a === 'object' && a.read); }","tryCatchPattern":"try { var html = karate.render(opts); } catch (e) { karate.warn('render failed: ' + e); }","preventionTips":["Always pass either a string path or a { read: ... } map to karate.render()","Verify path variables are non-null before render calls","Keep render calls close to where the path is defined"],"tags":["javascript","argument-validation","karate-js"],"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"}