apple/pkl · error · RendererException
Values of type `Duration` cannot be rendered as YAML. Value:
Error message
Values of type `Duration` cannot be rendered as YAML. Value: %s
What it means
The YAML renderer has no representation for Pkl Duration values, so visitDuration throws RendererException instead of emitting a scalar. Durations must be converted (e.g. to a number or ISO-8601 string) before rendering.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/YamlRenderer.java:144
@Override
public void visitInt(Long value) {
emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.INT));
}
@Override
public void visitFloat(Double value) {
emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.FLOAT));
}
@Override
public void visitBoolean(Boolean value) {
emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.BOOL));
}
@Override
public void visitDuration(Duration value) {
throw new RendererException(
String.format("Values of type `Duration` cannot be rendered as YAML. Value: %s", value));
}
@Override
public void visitDataSize(DataSize value) {
throw new RendererException(
String.format("Values of type `DataSize` cannot be rendered as YAML. Value: %s", value));
}
@Override
public void visitBytes(byte[] value) {
emitter.emit(YamlUtils.bytesScalar(value));
}
@Override
public void visitPair(Pair<?, ?> value) {
doVisitIterable(value, null);
}View on GitHub (pinned to f3efcbfc9b)
Solutions
- Convert Durations in the value to plain values first (e.g. `value.toUnit(Unit.Milliseconds).value` for a number).
- Render the duration as a string (value.toString(), e.g. "5.min") if consumers accept it.
- Keep durations out of the rendered document, or move them to a format/renderer that supports them (e.g. PCL/XML).
Example fix
// before
renderer.renderDocument(Map("timeout", 5.min)); // throws
// after
renderer.renderDocument(Map("timeoutMs", 5.min.toUnit(DurationUnit.Milliseconds).value)); Defensive patterns
Strategy: validation
Validate before calling
Map<String, Object> normalize(Map<String, Object> in) {
var out = new LinkedHashMap<String, Object>();
in.forEach((k, v) -> out.put(k, v instanceof Duration d ? d.toUnit(DurationUnit.Milliseconds).value : v));
return out;
} Type guard
boolean isYamlRenderable(Object v) {
return !(v instanceof Duration) && !(v instanceof DataSize) && !(v instanceof PClass);
} Try / catch
try {
renderer.renderDocument(value);
} catch (RendererException e) {
if (e.getMessage().startsWith("Values of type `Duration` cannot be rendered as YAML")) {
renderer.renderDocument(convertDurations(value));
} else throw e;
} Prevention
- Convert Duration values to numeric milliseconds/seconds at the Pkl level before export.
- Write a pre-render walker that rejects or converts non-primitive Pkl types.
- Add format-conversion tests covering configs with time fields.
When it happens
Trigger: renderDocument on a value tree that contains a property of type Duration (e.g. `timeout = 5.min`), reaching YamlRenderer.visitDuration.
Common situations: Rendering Pkl configs containing `5.min`, `30.s`, `1.h` values to YAML for tools that cannot understand them; output converters that pass raw Pkl values straight to the YAML renderer.
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 `DataSize` cannot be rendered as YAML. Value:
- Maps with non-String keys cannot currently be rendered as YA
- Values of type `Class` cannot be rendered as YAML. Value: %s
- The top-level value of a YAML stream must have type `Collect
- Maps containing non-String keys cannot be rendered as JSON.
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/0b0be90cf4f17e19.
Report an issue: GitHub.