apple/pkl · error · IOException
(request was rewritten: -> )
Error message
(request was rewritten: %s -> %s)
What it means
An IOException thrown during request sending is augmented with a note showing that the request URI was rewritten (e.g. pkl:// to http(s)://) before the underlying HTTP call. It tells the developer the actual wire URL differed from the logical URI they passed in, which matters when debugging connection failures.
Solutions
- Read the appended 'request was rewritten: X -> Y' note and debug connectivity against URL Y (proxy, DNS, firewall)
- Allowlist/proxy the rewritten host rather than the logical URI
- Retry with the rewritten URL directly to isolate the failure
Defensive patterns
Strategy: try-catch
Try / catch
try { var resp = client.send(request, handler, checker); } catch (IOException e) { if (e.getMessage() != null && e.getMessage().contains("request was rewritten:")) { /* debug the rewritten target URL, not the logical URI */ } throw e; } Prevention
- Note the rewritten target URL from the error message and test connectivity to it directly
- Configure proxies/firewalls for the rewritten host
- Keep a mapping of logical URIs to transport URLs
When it happens
Trigger: Any IOException from doSend (connect failure, timeout, DNS failure) while request.uri() differs from rewriteUri(request.uri()), i.e. the transport URL was rewritten from the original logical URI.
Common situations: Using pkl- or package-style URIs that get rewritten to real HTTP endpoints; users see the rewritten target URL in error messages and can check the correct host/proxy.
Related errors
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/56e23d6026e7650e.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java:164
currentRequestUri = rewriteUri(redirectUri);
currentRequest = rewriteRequest(request, currentRequestUri);
redirectCount++;
}
}
@Override
public <T> HttpResponse<T> send(
HttpRequest request,
BodyHandler<T> responseBodyHandler,
HttpRequestChecker httpRequestChecker)
throws IOException, SecurityManagerException {
checkNotClosed(request);
try {
return doSend(request, responseBodyHandler, httpRequestChecker);
} catch (IOException e) {
var rewrittenUri = rewriteUri(request.uri());
if (rewrittenUri != request.uri()) {
throw new IOException(
e.getMessage()
+ " (request was rewritten: %s -> %s)".formatted(request.uri(), rewrittenUri),
e);
}
throw e;
}
}
@Override
public void close() {
if (!closed.getAndSet(true)) delegate.close();
}
// Based on JDK 17's implementation of HttpRequest.newBuilder(HttpRequest, filter).
private HttpRequest rewriteRequest(HttpRequest original, URI newUri) {
HttpRequest.Builder builder = HttpRequest.newBuilder();
builderView on GitHub (pinned to f3efcbfc9b)