karatelabs/karate · error · RuntimeException
render() read arg should not be null
Error message
render() read arg should not be null
What it means
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.
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.
Example fix
// before
var path = karate.get('reportPath'); // may be null
var html = karate.render(path);
// after
var path = karate.get('reportPath') || 'report.feature';
var html = karate.render(path); Defensive patterns
Strategy: type-guard
Validate before calling
// JS if (path == null) path = 'report.feature'; var html = karate.render(path);
Type guard
function isNonNullTemplate(a) { return a != null; } Try / catch
try { var html = karate.render(arg); } catch (e) { if (String(e).indexOf('should not be null') >= 0) karate.warn('null template path'); throw e; } Prevention
- 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
When it happens
Trigger: `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).
Common situations: 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().
Related errors
- render() needs at least one argument
- karate.driver can only be read within a scenario
- karate.setup() is not available in this context
- toPrecision() precision must be between 1 and 100
- toExponential() fractionDigits must be between 0 and 100
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/eb2e8e8707a924d1.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJs.java:1108
}
/**
* karate.render(template) - Render HTML template (similar to doc).
* Returns the rendered HTML string without sending to doc consumer.
*/
@SuppressWarnings("unchecked")
private JavaInvokable render() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("render() needs at least one argument");
}
String readPath;
Map<String, Object> vars = null;
if (args[0] instanceof Map) {
Map<String, Object> map = (Map<String, Object>) args[0];
readPath = (String) map.get("read");
} else if (args[0] == null) {
throw new RuntimeException("render() read arg should not be null");
} else {
readPath = args[0] + "";
}
if (args.length > 1 && args[1] instanceof Map) {
vars = (Map<String, Object>) args[1];
}
return markup().processPath(readPath, vars);
};
}
/**
* karate.toAbsolutePath(path) - Convert a relative path to absolute.
* Resolves relative to the current feature file's directory.
*/
private JavaInvokable toAbsolutePath() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("toAbsolutePath() needs a path argument");View on GitHub (pinned to a22eb90246)