{"record":{"id":"ef7819dbe228161e","repo":"apple/pkl","slug":"values-of-type-datasize-cannot-be-rendered-as-ya","errorCode":null,"errorMessage":"Values of type `DataSize` cannot be rendered as YAML. Value: %s","messagePattern":"Values of type `DataSize` 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":150,"sourceCode":"    @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    }\n\n    @Override\n    public void visitList(List<?> value) {\n      doVisitIterable(value, null);\n    }\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/YamlRenderer.java#L132-L168","documentation":"RendererException thrown by YamlRenderer.visitDataSize: the YAML emitter has no scalar representation for pkl DataSize values (unlike numbers, strings, booleans), so any DataSize reaching YAML output aborts rendering. The same renderer rejects Duration the same way, indicating deliberate exclusion of these typed values.","triggerScenarios":"renderDocument on a tree containing a DataSize property (e.g. `maxSize = 5.mb`), reaching YamlRenderer.visitDataSize.","commonSituations":"Configs with `1.gib`, `500.kib` byte-size values being exported to YAML; generic value pipelines that don't pre-convert DataSize.","solutions":["Convert the DataSize to a plain number or string (e.g. value.toUnit(DataSizeUnit.KIB) or toString()) before rendering.","Convert the Pkl object to a Map/List with only YAML-representable types and render that."],"exampleFix":"// before\nrenderer.renderDocument(Map(\"maxSize\", 5.mb)); // throws\n// after\nrenderer.renderDocument(Map(\"maxSizeBytes\", 5.mb.toUnit(DataSizeUnit.Bytes).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 DataSize d ? d.toUnit(DataSizeUnit.Bytes).value : v));\n  return out;\n}","typeGuard":"boolean isYamlRenderable(Object v) {\n  return !(v instanceof DataSize) && !(v instanceof Duration) && !(v instanceof PClass);\n}","tryCatchPattern":"try {\n  renderer.renderDocument(value);\n} catch (RendererException e) {\n  if (e.getMessage().startsWith(\"Values of type `DataSize` cannot be rendered as YAML\")) {\n    renderer.renderDocument(convertDataSizes(value));\n  } else throw e;\n}","preventionTips":["Express sizes as plain byte counts in documents destined for YAML.","Run a sanitizing pass converting DataSize via toUnit(DataSizeUnit.Bytes).value.","Include size-valued fields in renderer unit tests."],"tags":["yaml","rendering","data-size","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"}