apple/pkl · error
adhocEvalError
Error message
adhocEvalError
What it means
Thrown by String.fromBase64() (decoded as UTF-8 text) when the input is not valid Base64. Java's Base64 decoder rejects illegal characters, incorrect padding, or lengths that are not a multiple of 4; the decoder's message is surfaced with the offending string attached.
Solutions
- Verify the string is valid Base64 (length multiple of 4, correct padding, alphabet A–Z a–z 0–9 + /)
- Strip any data-URI prefix and whitespace before decoding
- Convert URL-safe characters: replace '-' with '+' and '_' with '/' for JWT-style payloads
- Re-encode the source data if the payload is truncated or corrupt
Example fix
// before
val text = jwtPayload.fromBase64()
// after
val text = jwtPayload.replace("-", "+").replace("_", "/").fromBase64() Defensive patterns
Strategy: validation
Validate before calling
function isStandardBase64(s: String): Boolean = s.replaceAll("\n", "").isRegexMatch(/^[A-Za-z0-9+/]*={0,2}$/, _) && s.replaceAll("\n", "").length % 4 == 0 Prevention
- Validate the Base64 alphabet and padding before decoding
- Strip data-URI prefixes and whitespace
- Convert base64url (-, _) to standard base64 first
When it happens
Trigger: Calling `"not~base64!".fromBase64()`, a Base64 string with wrong padding (e.g. "YWJ"), URL-safe base64 (- and _) fed to the standard decoder, or an empty/malformed payload from an API.
Common situations: Copying tokens or credentials that got truncated or whitespace-mangled; receiving base64url (JWT segments) instead of standard base64; data-URI prefixes ("data:...;base64,") left in the string.
Related errors
- e.getMessage()
- Cannot convert pkl.base#String
- Cannot decode Function value
- cannotParseStringAs
- charIndexOutOfRange
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/18bc340614558382.
Report an issue: GitHub.
Appendix: source
Thrown at pkl-core/src/main/java/org/pkl/core/stdlib/base/StringNodes.java:1006
}
}
public abstract static class base64 extends ExternalPropertyNode {
@TruffleBoundary
@Specialization
protected String eval(String self) {
return ByteArrayUtils.base64(self.getBytes(StandardCharsets.UTF_8));
}
}
public abstract static class base64Decoded extends ExternalPropertyNode {
@TruffleBoundary
@Specialization
protected String eval(String self) {
try {
return new String(Base64.getDecoder().decode(self), StandardCharsets.UTF_8);
} catch (IllegalArgumentException e) {
throw exceptionBuilder()
.adhocEvalError(e.getMessage())
.withProgramValue("String", self)
.withCause(e)
.build();
}
}
}
public abstract static class base64DecodedBytes extends ExternalPropertyNode {
@TruffleBoundary
@Specialization
protected VmBytes eval(String self) {
try {
return new VmBytes(Base64.getDecoder().decode(self));
} catch (IllegalArgumentException e) {
throw exceptionBuilder()
.adhocEvalError(e.getMessage())
.withProgramValue("String", self)View on GitHub (pinned to f3efcbfc9b)