karatelabs/karate · error · RuntimeException

Resource resolver not configured

Error message

Resource resolver not configured

What it means

ServerMarkupContext.read() resolves template/resource paths through a configurable resourceResolver function. If no resolver was configured before the context is used, it throws this RuntimeException instead of failing later with a NullPointerException. It indicates the server markup context was constructed without wiring resource loading.

Solutions

  1. Configure the resource resolver when creating the ServerMarkupContext / server (pass the path-resolution lambda).
  2. Use the standard Karate server bootstrap so the resolver is wired automatically.
  3. Guard template code so read() is only called when a resolver is present.
  4. In tests, construct the context via the same factory the server uses, not new ServerMarkupContext() directly.

Example fix

// before
ServerMarkupContext ctx = new ServerMarkupContext();
// after
ServerMarkupContext ctx = new ServerMarkupContext(resourceResolver, ...); // resolver wired
Defensive patterns

Strategy: validation

Validate before calling

// Java
if (resolver == null) throw new IllegalStateException("ServerMarkupContext created without a resource resolver");

Try / catch

try {
    String tpl = ctx.read(path);
} catch (RuntimeException e) {
    if (e.getMessage().contains("Resource resolver not configured")) {
        throw new IllegalStateException("Server misconfigured: resolver missing", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Rendering server-side markup (templates, includes) on a Karate mock/server where read(path) is invoked but the builder/constructor path that sets resourceResolver was never exercised — e.g. using a ServerMarkupContext created without a resource resolver argument.

Common situations: Custom server extensions or plugins that call context.read() inside templates; refactors that construct ServerMarkupContext directly in tests; forgetting to install the resolver when embedding the Karate server in an application.

Understand the failure class

Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java:191

        }
    }

    // MarkupContext implementation

    @Override
    public String getTemplateName() {
        return templateName;
    }

    @Override
    public String getCallerTemplateName() {
        return callerTemplateName;
    }

    @Override
    public String read(String path) {
        if (resourceResolver == null) {
            throw new RuntimeException("Resource resolver not configured");
        }
        Resource resource = resourceResolver.apply(path);
        return resource.getText();
    }

    @Override
    public byte[] readBytes(String path) {
        if (resourceResolver == null) {
            throw new RuntimeException("Resource resolver not configured");
        }
        Resource resource = resourceResolver.apply(path);
        return FileUtils.toBytes(resource.getStream());
    }

    @Override
    public String toJson(Object obj) {
        return Json.stringifyStrict(obj);
    }

View on GitHub (pinned to a22eb90246)