{"record":{"id":"0c60fb23dd836b8c","repo":"apple/pkl","slug":"failed-to-parse-hostname-in-no-proxy-rule-repr","errorCode":null,"errorMessage":"Failed to parse hostname in no-proxy rule: ${repr}","messagePattern":"Failed to parse hostname in no-proxy rule: (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/http/NoProxyRule.java","lineNumber":107,"sourceCode":"          hostname = repr;\n          return;\n        }\n        ipv6Mask = new BigInteger(1, maskBuffer.array()).not().shiftRight(prefixLength);\n      }\n      if (ipv6Matcher.group(\"port\") != null) {\n        port = Integer.parseInt(ipv6Matcher.group(\"port\"));\n      }\n      return;\n    }\n    var hostnameMatcher = hostnamePattern.matcher(repr);\n    if (hostnameMatcher.matches()) {\n      hostname = hostnameMatcher.group(\"host\");\n      if (hostnameMatcher.group(\"port\") != null) {\n        port = Integer.parseInt(hostnameMatcher.group(\"port\"));\n      }\n      return;\n    }\n    throw new RuntimeException(\"Failed to parse hostname in no-proxy rule: \" + repr);\n  }\n\n  public boolean matches(URI uri) {\n    if (allNoProxy) {\n      return true;\n    }\n    if (!hostMatches(uri)) {\n      return false;\n    }\n    if (port == 0) {\n      return true;\n    }\n    var thatPort = uri.getPort();\n    if (thatPort == -1) {\n      thatPort =\n          switch (uri.getScheme()) {\n            case \"http\" -> 80;\n            case \"https\" -> 443;","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/http/NoProxyRule.java#L89-L125","documentation":"Pkl failed to parse the hostname portion of an entry in the NO_PROXY / no_proxy environment value. NoProxyRule parses each comma-separated rule and throws this RuntimeException when a rule does not match the expected host[:port] pattern syntax.","triggerScenarios":"Setting NO_PROXY (or http.noProxy config) with an entry whose hostname part cannot be parsed by the rule regex, e.g. malformed URL-ish entries like `https://host`, brackets/whitespace oddities, or an invalid port (`host:port`, non-numeric port). NoProxyRule's public constructor throws this.","commonSituations":"Hand-edited NO_PROXY values with typos (`host::8080`, `host:notaport`), pasting full URLs instead of hostnames, copy-pasting rules with stray characters or scheme prefixes.","solutions":["Print the no_proxy value (`echo $NO_PROXY` / `echo $no_proxy`) and find the malformed entry mentioned in `${repr}`.","Rewrite each entry as `host` or `host:port` only — no scheme (https://) or path.","Remove or fix the invalid entry and retry the Pkl command.","Keep the value to comma-separated hostnames, domains (with leading dot), and optional numeric ports.","Prefer a library-managed or generated no_proxy list rather than manual edits."],"exampleFix":"// before (shell)\nexport NO_PROXY=\"https://internal.example.com,localhost:8080x\"\n// after (shell)\nexport NO_PROXY=\"internal.example.com,localhost:8080\"","handlingStrategy":"validation","validationCode":"for (String rule : System.getenv(\"NO_PROXY\").split(\",\")) {\n  String r = rule.strip();\n  if (r.contains(\"://\") || !r.matches(\"(\\\\*|\\\\.?[^:,\\\\s]+)(:\\\\d+)?\")) {\n    throw new IllegalStateException(\"Malformed NO_PROXY entry: \" + r);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  // run Pkl\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Failed to parse hostname in no-proxy rule\")) {\n    // fix the offending entry printed in the message\n  }\n}","preventionTips":["Keep NO_PROXY entries as bare hostnames/domains with optional :port only.","Never put full URLs (with scheme/path) in NO_PROXY.","Lint proxy env vars in CI/startup scripts.","Generate no_proxy lists programmatically instead of hand-editing."],"tags":["http","proxy","no-proxy","environment-variable","parsing"],"backgroundTag":"invalid-env-var-value","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"}