{"record":{"id":"7e36b17c115203bc","repo":"karatelabs/karate","slug":"doc-read-arg-should-not-be-null","errorCode":null,"errorMessage":"doc() read arg should not be null","messagePattern":"doc\\(\\) 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":183,"sourceCode":"        return args -> {\n            if (onDoc == null) {\n                logger.warn(\"doc() called, but no destination set\");\n                return null;\n            }\n            if (args.length == 0) {\n                throw new RuntimeException(\"doc() needs at least one argument\");\n            }\n            String read;\n            if (args[0] instanceof Map) {\n                Map<String, Object> map = (Map<String, Object>) args[0];\n                read = (String) map.get(\"read\");\n            } else if (args[0] == null) {\n                read = null;\n            } else {\n                read = args[0] + \"\";\n            }\n            if (read == null) {\n                throw new RuntimeException(\"doc() read arg should not be null\");\n            }\n            Map<String, Object> vars;\n            if (args.length > 1) {\n                vars = (Map<String, Object>) args[1];\n            } else {\n                vars = null;\n            }\n            String html = markup().processPath(read, vars);\n            onDoc.accept(html);\n            return null;\n        };\n    }\n\n    // ========== Engine-Dependent Methods ==========\n    // These methods require access to the JavaScript engine for evaluation.\n\n    private JavaCallable initRead() {\n        return (context, args) -> {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJs.java#L165-L201","documentation":"After extracting the 'read' value from doc()'s first argument (map, null, or string-coerced value), Karate requires it to be non-null. An explicit null — e.g. doc(null) or doc({ read: null }) — throws this error since there is no template to render.","triggerScenarios":"Calling karate.doc(null), or doc({ read: someVar }) where someVar is null/undefined; a config or variable that should hold a path but was never set.","commonSituations":"Environment-specific path variables not initialized for the active environment; reading the path from a config map with a misspelled key; conditional logic that skips assigning the template path.","solutions":["Verify the variable holding the template path is set before calling doc()","Default the path: read = path || 'classpath:doc/default.html'","Check the config/env map key that supplies the path for typos"],"exampleFix":"// before\n* doc({ read: docPath })   // docPath is undefined in this env\n// after\n* def docPath = karate.env == 'dev' ? 'classpath:doc/dev.html' : 'classpath:doc/default.html'\n* doc({ read: docPath })","handlingStrategy":"validation","validationCode":"if (readPath == null) { readPath = 'classpath:doc/default.html'; }","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.length > 0; }","tryCatchPattern":"try { karate.doc(readPath); } catch (RuntimeException e) { if (e.getMessage().contains('read arg should not be null')) { log.error('template path variable is null — check env config'); } throw e; }","preventionTips":["Initialize path variables per environment in karate-config.js","Use defaults with || for optional paths","Grep for doc( calls and confirm their path sources are set"],"tags":["doc","null-argument","templates","javascript"],"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"}