{"record":{"id":"20471e664f3d5914","repo":"karatelabs/karate","slug":"resource-resolver-not-configured","errorCode":null,"errorMessage":"Resource resolver not configured","messagePattern":"Resource resolver not configured","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java","lineNumber":191,"sourceCode":"        }\n    }\n\n    // MarkupContext implementation\n\n    @Override\n    public String getTemplateName() {\n        return templateName;\n    }\n\n    @Override\n    public String getCallerTemplateName() {\n        return callerTemplateName;\n    }\n\n    @Override\n    public String read(String path) {\n        if (resourceResolver == null) {\n            throw new RuntimeException(\"Resource resolver not configured\");\n        }\n        Resource resource = resourceResolver.apply(path);\n        return resource.getText();\n    }\n\n    @Override\n    public byte[] readBytes(String path) {\n        if (resourceResolver == null) {\n            throw new RuntimeException(\"Resource resolver not configured\");\n        }\n        Resource resource = resourceResolver.apply(path);\n        return FileUtils.toBytes(resource.getStream());\n    }\n\n    @Override\n    public String toJson(Object obj) {\n        return Json.stringifyStrict(obj);\n    }","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/http/ServerMarkupContext.java#L173-L209","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nServerMarkupContext ctx = new ServerMarkupContext();\n// after\nServerMarkupContext ctx = new ServerMarkupContext(resourceResolver, ...); // resolver wired","handlingStrategy":"validation","validationCode":"// Java\nif (resolver == null) throw new IllegalStateException(\"ServerMarkupContext created without a resource resolver\");","typeGuard":null,"tryCatchPattern":"try {\n    String tpl = ctx.read(path);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Resource resolver not configured\")) {\n        throw new IllegalStateException(\"Server misconfigured: resolver missing\", e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["server","configuration","templates"],"backgroundTag":"missing-required-config","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}