karatelabs/karate · error · RuntimeException

render() needs at least one argument

Error message

render() needs at least one argument

What it means

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.

Solutions

  1. Pass the template/feature path as the first argument: karate.render('report.feature')
  2. Pass an options map with a 'read' key: karate.render({ read: 'report.feature', var1: 'x' })
  3. If the path is dynamic, verify the variable is defined before the call and not undefined/null.

Example fix

// before
var html = karate.render();
// after
var html = karate.render({ read: 'report.feature' });
Defensive patterns

Strategy: validation

Validate before calling

// JS
if (path == null) karate.fail('karate.render() requires a read path');
var html = karate.render(path);

Type guard

function isRenderableArg(a) { return typeof a === 'string' || (a && typeof a === 'object' && a.read); }

Try / catch

try { var html = karate.render(opts); } catch (e) { karate.warn('render failed: ' + e); }

Prevention

When it happens

Trigger: 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' })`.

Common situations: 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).

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/fe6b0ee036a067ce. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/core/KarateJs.java:1100

            String path = args[0] + "";
            Resource resource = getCurrentResource().resolve(path);
            try {
                return resource.getStream();
            } catch (Exception e) {
                throw new RuntimeException("Failed to open stream for: " + path, e);
            }
        };
    }

    /**
     * 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);
        };
    }

View on GitHub (pinned to a22eb90246)