{"record":{"id":"0b0be90cf4f17e19","repo":"apple/pkl","slug":"values-of-type-duration-cannot-be-rendered-as-ya","errorCode":null,"errorMessage":"Values of type `Duration` cannot be rendered as YAML. Value: %s","messagePattern":"Values of type `Duration` cannot be rendered as YAML\\. Value: (.+?)","errorType":"exception","errorClass":"RendererException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/YamlRenderer.java","lineNumber":144,"sourceCode":"\n    @Override\n    public void visitInt(Long value) {\n      emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.INT));\n    }\n\n    @Override\n    public void visitFloat(Double value) {\n      emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.FLOAT));\n    }\n\n    @Override\n    public void visitBoolean(Boolean value) {\n      emitter.emit(YamlUtils.plainScalar(value.toString(), Tag.BOOL));\n    }\n\n    @Override\n    public void visitDuration(Duration value) {\n      throw new RendererException(\n          String.format(\"Values of type `Duration` cannot be rendered as YAML. Value: %s\", value));\n    }\n\n    @Override\n    public void visitDataSize(DataSize value) {\n      throw new RendererException(\n          String.format(\"Values of type `DataSize` cannot be rendered as YAML. Value: %s\", value));\n    }\n\n    @Override\n    public void visitBytes(byte[] value) {\n      emitter.emit(YamlUtils.bytesScalar(value));\n    }\n\n    @Override\n    public void visitPair(Pair<?, ?> value) {\n      doVisitIterable(value, null);\n    }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/YamlRenderer.java#L126-L162","documentation":"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.","triggerScenarios":"renderDocument on a value tree that contains a property of type Duration (e.g. `timeout = 5.min`), reaching YamlRenderer.visitDuration.","commonSituations":"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.","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)."],"exampleFix":"// before\nrenderer.renderDocument(Map(\"timeout\", 5.min)); // throws\n// after\nrenderer.renderDocument(Map(\"timeoutMs\", 5.min.toUnit(DurationUnit.Milliseconds).value));","handlingStrategy":"validation","validationCode":"Map<String, Object> normalize(Map<String, Object> in) {\n  var out = new LinkedHashMap<String, Object>();\n  in.forEach((k, v) -> out.put(k, v instanceof Duration d ? d.toUnit(DurationUnit.Milliseconds).value : v));\n  return out;\n}","typeGuard":"boolean isYamlRenderable(Object v) {\n  return !(v instanceof Duration) && !(v instanceof DataSize) && !(v instanceof PClass);\n}","tryCatchPattern":"try {\n  renderer.renderDocument(value);\n} catch (RendererException e) {\n  if (e.getMessage().startsWith(\"Values of type `Duration` cannot be rendered as YAML\")) {\n    renderer.renderDocument(convertDurations(value));\n  } else throw e;\n}","preventionTips":["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."],"tags":["yaml","rendering","duration","pkl","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}