apple/pkl · error · RuntimeException
Failed to parse hostname in no-proxy rule: ${repr}
Error message
Failed to parse hostname in no-proxy rule: ${repr} What it means
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.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/http/NoProxyRule.java:107
hostname = repr;
return;
}
ipv6Mask = new BigInteger(1, maskBuffer.array()).not().shiftRight(prefixLength);
}
if (ipv6Matcher.group("port") != null) {
port = Integer.parseInt(ipv6Matcher.group("port"));
}
return;
}
var hostnameMatcher = hostnamePattern.matcher(repr);
if (hostnameMatcher.matches()) {
hostname = hostnameMatcher.group("host");
if (hostnameMatcher.group("port") != null) {
port = Integer.parseInt(hostnameMatcher.group("port"));
}
return;
}
throw new RuntimeException("Failed to parse hostname in no-proxy rule: " + repr);
}
public boolean matches(URI uri) {
if (allNoProxy) {
return true;
}
if (!hostMatches(uri)) {
return false;
}
if (port == 0) {
return true;
}
var thatPort = uri.getPort();
if (thatPort == -1) {
thatPort =
switch (uri.getScheme()) {
case "http" -> 80;
case "https" -> 443;View on GitHub (pinned to f3efcbfc9b)
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.
Example fix
// before (shell) export NO_PROXY="https://internal.example.com,localhost:8080x" // after (shell) export NO_PROXY="internal.example.com,localhost:8080"
Defensive patterns
Strategy: validation
Validate before calling
for (String rule : System.getenv("NO_PROXY").split(",")) {
String r = rule.strip();
if (r.contains("://") || !r.matches("(\\*|\\.?[^:,\\s]+)(:\\d+)?")) {
throw new IllegalStateException("Malformed NO_PROXY entry: " + r);
}
} Try / catch
try {
// run Pkl
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Failed to parse hostname in no-proxy rule")) {
// fix the offending entry printed in the message
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- cannotParseCertFile
- malformedProxyAddress
- `%s` is too large to fit into a Version.
- `%s` could not be parsed as a semantic version number.
- invalidUri
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/0c60fb23dd836b8c.
Report an issue: GitHub.