apple/pkl · error · RendererException
Values of type `Regex` cannot be rendered as YAML. Value: %s
Error message
Values of type `Regex` cannot be rendered as YAML. Value: %s
What it means
The YAML renderer does not support java.util.regex.Pattern values. Pkl Regex values are patterns, not renderable data, so visitRegex throws a RendererException rather than emitting a guessable representation. The error exists to fail fast instead of silently rendering a misleading string form.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/YamlRenderer.java:223
value.getSimpleName()));
}
@Override
public void visitTypeAlias(TypeAlias value) {
throw new RendererException(
String.format(
"Values of type `TypeAlias` cannot be rendered as YAML. Value: %s",
value.getSimpleName()));
}
@Override
public void visitNull() {
emitter.emit(YamlUtils.plainScalar("null", Tag.NULL));
}
@Override
public void visitRegex(Pattern value) {
throw new RendererException(
String.format("Values of type `Regex` cannot be rendered as YAML. Value: %s", value));
}
private void doVisitIterable(Iterable<?> iterable, @Nullable String tag) {
emitter.emit(
new SequenceStartEvent(
Optional.empty(), Optional.ofNullable(tag), true, FlowStyle.BLOCK));
for (var elem : iterable) visit(elem);
emitter.emit(new SequenceEndEvent(Optional.empty(), Optional.empty()));
}
private void doVisitProperties(Map<String, ?> properties) {
emitter.emit(
new MappingStartEvent(Optional.empty(), Optional.empty(), true, FlowStyle.BLOCK));
for (var entry : properties.entrySet()) {
var value = entry.getValue();
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Convert the Regex to a string before rendering (render its pattern source instead of the Pattern object).
- Exclude regex/validation properties from the rendered document (e.g. keep them hidden or in a separate non-output module).
- If YAML must contain the pattern, wrap it in a String-typed property holding the pattern text.
Example fix
// before (Pkl)
output {
["pattern"] = myRegex
}
// after
output {
["pattern"] = myRegex.patternString
} Defensive patterns
Strategy: validation
Validate before calling
// before rendering
if (anyValue is java.util.regex.Pattern || valueIsPklRegex(value)) {
throw IllegalArgumentException("Convert Regex to its pattern string before YAML rendering")
} Type guard
fun isYamlRenderable(v: Any?): Boolean = v !is java.util.regex.Pattern && (v == null || v is String || v is Number || v is Boolean || v is List<*> || v is Map<*, *> || v is org.pkl.core.runtime.VmObject)
Prevention
- Convert Regex values to pattern strings before output rendering.
- Keep validation-only regex properties out of output documents.
- Declare output properties as String when they hold pattern text.
When it happens
Trigger: Rendering a property whose value is a Regex (e.g. a property declared as `regex` or produced by Regex(#"...")`) via YamlRenderer, or including a Regex-valued member in an object passed to YAML output.
Common situations: Validation-heavy configs where pattern properties live next to data properties and a tool renders the whole module to YAML; forgetting to convert a Regex to its .patternString before output.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Values of type `TypeAlias` cannot be rendered as YAML. Value
- invalidYamlStreamTopLevelValue
- Failed to convert `pkl.base#String` to `java.util.regex.Patt
- Type mappings are not supported for array types.
- Values of type `Duration` cannot be rendered as JSON. Value:
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/6e8179bd8177519f.
Report an issue: GitHub.