apple/pkl · error · PklException
invalidUri
invalidUri
Error message
invalidUri: ${input} What it means
PklEvaluatorSettings.parseHttpRewrites converts the http proxy 'rewrites' map entries from strings to java.net.URI objects. When any key or value string is not a valid URI per RFC 2396, URI() throws URISyntaxException and this PklException with code 'invalidUri' is thrown, embedding the offending input string.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/evaluatorSettings/PklEvaluatorSettings.java:154
return new Http(proxy, parsedRewrites, parsedHeaders);
} else {
throw PklBugException.unreachableCode();
}
}
@SuppressWarnings("unchecked")
private static @Nullable Map<URI, URI> parseHttpRewrites(Object rewrites) {
if (rewrites instanceof PNull) {
return null;
}
var parsedRewrites = new HashMap<URI, URI>();
for (var entry : ((Map<String, String>) rewrites).entrySet()) {
var key = entry.getKey();
var value = entry.getValue();
try {
parsedRewrites.put(new URI(key), new URI(value));
} catch (URISyntaxException e) {
throw new PklException(ErrorMessages.create("invalidUri", e.getInput()));
}
}
return parsedRewrites;
}
@SuppressWarnings("unchecked")
private static @Nullable Map<String, Map<String, List<String>>> parseHttpHeaders(
Object headerDefs) {
if (headerDefs instanceof PNull) {
return null;
}
var defs = (Map<String, Map<String, Object>>) headerDefs;
var ret = new LinkedHashMap<String, Map<String, List<String>>>(defs.size());
for (var entry : defs.entrySet()) {
var headers = entry.getValue();
var map = new LinkedHashMap<String, List<String>>(headers.size());
for (var header : headers.entrySet()) {
var value = header.getValue();View on GitHub (pinned to f3efcbfc9b)
Solutions
- Print and inspect the offending string in the error message; fix the key or value in the rewrites map to be a valid URI
- Add an explicit scheme (http:// or https://) to the URL
- URL-encode illegal characters (spaces, non-ASCII) or strip them
- Trim whitespace and stray quotes from the map key/value
Example fix
// before
"http": { rewrites: { "old.example.com": "new.example.com" } }
// after
"http": { rewrites: { "https://old.example.com": "https://new.example.com" } } Defensive patterns
Strategy: validation
Validate before calling
static URI requireUri(String s) {
try { return new URI(s.trim()); }
catch (URISyntaxException e) { throw new IllegalArgumentException("Not a valid URI: " + s, e); }
}
// validate each key/value of the rewrites map before constructing PklEvaluatorSettings Type guard
boolean isValidUri(String s) {
if (s == null) return false;
try { new URI(s.trim()); return true; } catch (URISyntaxException e) { return false; }
} Try / catch
try {
evaluatorSettings.apply(...);
} catch (PklException e) {
if (e.getMessage().startsWith("invalidUri")) {
// surface the offending string from the message and fix the config
}
} Prevention
- Always include an explicit scheme in rewrite keys and values
- Trim whitespace from config strings read from files/env vars
- Validate all rewrite map entries with new URI(...) at config-load time
- Avoid raw templating placeholders like ${...} in URLs
When it happens
Trigger: Calling PklEvaluatorSettings with an http rewrites map whose key or value (e.g. 'https://old.com' -> 'https://new.com') fails URI parsing — malformed scheme, illegal characters like spaces or '{', or missing scheme.
Common situations: Typos in rewrite URLs (missing scheme like 'new.example.com'), unencoded characters in URLs, templated values not yet interpolated, copy-pasted URLs with surrounding whitespace or quotes.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- Failed to convert `pkl.base#String` to `java.net.URI`.
- No security manager set.
- malformedProxyAddress
- invalidUriMissingFragment
- cannotHaveRelativeFragment
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/b3b4c0cc3b524753.
Report an issue: GitHub.