karatelabs/karate · error · RuntimeException
http client not set
Error message
http client not set
What it means
HttpRequestBuilder.invoke() sends the built HttpRequest through the configured HttpClient. The builder was created without a client (never passed via the constructor or a setter), so there is nothing to execute the request with, and the builder throws before doing any I/O.
Solutions
- Create and set a client: new HttpRequestBuilder(new DefaultHttpClientFactory().create())
- Prefer high-level entry points such as karate.http(...) / HttpRequest helpers that wire a client for you
- If you only need a curl representation, call toCurlCommand() instead of invoke()
- Audit custom integration code for builders constructed without a client parameter
Example fix
// before
HttpRequestBuilder builder = new HttpRequestBuilder();
builder.url("http://example.com").invoke(); // throws
// after
HttpRequestBuilder builder = new HttpRequestBuilder(new DefaultHttpClientFactory().create());
builder.url("http://example.com").invoke(); Defensive patterns
Strategy: try-catch
Validate before calling
if (client == null) throw new IllegalStateException('set an HttpClient on the builder before invoke()'); Try / catch
try {
builder.invoke();
} catch (RuntimeException e) {
if (e.getMessage().equals("http client not set")) {
builder = new HttpRequestBuilder(new DefaultHttpClientFactory().create()).url(builderUrl);
// retry the invoke
} else { throw e; }
} Prevention
- Construct builders with a client: new HttpRequestBuilder(httpClient)
- Prefer karate.http(...) or library helpers that wire a client automatically
- Use toCurlCommand() for inspection-only flows instead of invoking a client-less builder
When it happens
Trigger: Calling invoke()/response()/method()/request()/proceed()/exception() on an HttpRequestBuilder constructed with new HttpRequestBuilder() and no client set; obtaining a builder through a code path that bypasses the HttpClientFactory; holding a builder beyond a scope where its client was reset.
Common situations: Embedding Karate's HTTP DSL in custom Java code and forgetting to create a client via new DefaultHttpClientFactory().create(); framework integrations that build requests for serialization (curl export) but then attempt to execute them; configuration errors where the client bean was never injected.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- incomplete http request, 'url' not set
- pool sizes must be at least 1, got maxTotal= perRoute=
- session is unavailable: no sessionStore is configured. Call…
- session is unavailable: no sessionStore is configured. Call…
- boot.classpath: dir is null — pass a project-relative…
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/4728975919fdd1c3.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java:143
request.setUrl(getUri());
if (multiPart != null) {
request.setBodyDisplay(multiPart.getBodyForDisplay());
}
if (body != null) {
request.setBody(Json.toBytes(body));
}
request.setHeaders(headers);
// Also set params on request so InMemoryHttpClient and others can access them
if (params != null) {
request.setParams(params);
}
return request;
}
public HttpResponse invoke() {
HttpRequest request = build();
if (client == null) {
throw new RuntimeException("http client not set");
}
reset();
HttpResponse response = client.invoke(request);
response.setRequest(request);
// conversion-side stamp for ANY client, on every lane that reaches this builder —
// the step executor re-stamps the gherkin lanes, but karate.http() has only this
if (configSupplier != null) {
io.karatelabs.core.KarateConfig config = configSupplier.get();
if (config != null) {
response.setStrictParsing(config.isStrictResponseParsing());
}
}
return response;
}
public HttpResponse invoke(String method) {
this.method = method;
return invoke();View on GitHub (pinned to a22eb90246)