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
- Configure the resource resolver when creating the ServerMarkupContext / server (pass the path-resolution lambda).
- Use the standard Karate server bootstrap so the resolver is wired automatically.
- Guard template code so read() is only called when a resolver is present.
- 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
- Always construct the context through the server's bootstrap/factory
- Add a construction-time assertion that the resolver is set
- Cover template rendering in smoke tests
- Don't instantiate ServerMarkupContext directly in custom code
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
- switch() requires a template argument
- at least one feature file is required
- boot.classpath(' '): expected a directory RELATIVE to the…
- boot.classpath: dir is null — pass a project-relative…
- boot.read: path is null
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)