{"record":{"id":"56e23d6026e7650e","repo":"apple/pkl","slug":"request-was-rewritten-s-s","errorCode":null,"errorMessage":"(request was rewritten: %s -> %s)","messagePattern":"\\(request was rewritten: (.+?) -> (.+?)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java","lineNumber":164,"sourceCode":"      currentRequestUri = rewriteUri(redirectUri);\n      currentRequest = rewriteRequest(request, currentRequestUri);\n      redirectCount++;\n    }\n  }\n\n  @Override\n  public <T> HttpResponse<T> send(\n      HttpRequest request,\n      BodyHandler<T> responseBodyHandler,\n      HttpRequestChecker httpRequestChecker)\n      throws IOException, SecurityManagerException {\n    checkNotClosed(request);\n    try {\n      return doSend(request, responseBodyHandler, httpRequestChecker);\n    } catch (IOException e) {\n      var rewrittenUri = rewriteUri(request.uri());\n      if (rewrittenUri != request.uri()) {\n        throw new IOException(\n            e.getMessage()\n                + \" (request was rewritten: %s -> %s)\".formatted(request.uri(), rewrittenUri),\n            e);\n      }\n      throw e;\n    }\n  }\n\n  @Override\n  public void close() {\n    if (!closed.getAndSet(true)) delegate.close();\n  }\n\n  // Based on JDK 17's implementation of HttpRequest.newBuilder(HttpRequest, filter).\n  private HttpRequest rewriteRequest(HttpRequest original, URI newUri) {\n    HttpRequest.Builder builder = HttpRequest.newBuilder();\n\n    builder","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/http/RequestRewritingClient.java#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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"],"tags":["http","io","uri-rewrite"],"backgroundTag":"network-request-failed","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}