{"record":{"id":"eb2e8e8707a924d1","repo":"karatelabs/karate","slug":"render-read-arg-should-not-be-null","errorCode":null,"errorMessage":"render() read arg should not be null","messagePattern":"render\\(\\) read arg should not be null","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJs.java","lineNumber":1108,"sourceCode":"    }\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\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\");","sourceCodeStart":1090,"sourceCodeEnd":1126,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L1090-L1126","documentation":"When karate.render() receives a single argument that is explicitly null (and not a Map or string), the library cannot determine what to render and throws this error. A null first argument is distinct from a missing one, so it gets its own guard.","triggerScenarios":"`karate.render(null)` directly, or `karate.render(someVar)` where someVar evaluates to null at runtime (e.g. a config value or response field that was null).","commonSituations":"A variable holding the template path was never set or came back null from a previous API call; reading a key from a config map that does not exist yields null and is then passed straight to render().","solutions":["Check the variable for null before calling render() and provide a default path","Pass a string or { read: '...' } map instead of null","Trace where the null came from (missing config key, absent response field) and fix the source."],"exampleFix":"// before\nvar path = karate.get('reportPath'); // may be null\nvar html = karate.render(path);\n// after\nvar path = karate.get('reportPath') || 'report.feature';\nvar html = karate.render(path);","handlingStrategy":"type-guard","validationCode":"// JS\nif (path == null) path = 'report.feature';\nvar html = karate.render(path);","typeGuard":"function isNonNullTemplate(a) { return a != null; }","tryCatchPattern":"try { var html = karate.render(arg); } catch (e) { if (String(e).indexOf('should not be null') >= 0) karate.warn('null template path'); throw e; }","preventionTips":["Default-null template path variables before use","Don't pass config lookups straight into render() without a null check","Log/inspect the variable when a null path is possible"],"tags":["javascript","null-value","karate-js"],"backgroundTag":"null-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"}