apple/pkl · error · IOException

(request was rewritten: %s -> %s)

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.

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();

    builder

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Read the appended 'request was rewritten: X -> Y' note and debug connectivity against URL Y (proxy, DNS, firewall)
  2. Allowlist/proxy the rewritten host rather than the logical URI
  3. 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

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.