apple/pkl · error · RendererException

Values of type `DataSize` cannot be rendered as YAML. Value:

Error message

Values of type `DataSize` cannot be rendered as YAML. Value: %s

What it means

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.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/YamlRenderer.java:150

    @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);
    }

    @Override
    public void visitList(List<?> value) {
      doVisitIterable(value, null);
    }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Convert the DataSize to a plain number or string (e.g. value.toUnit(DataSizeUnit.KIB) or toString()) before rendering.
  2. Convert the Pkl object to a Map/List with only YAML-representable types and render that.

Example fix

// before
renderer.renderDocument(Map("maxSize", 5.mb)); // throws
// after
renderer.renderDocument(Map("maxSizeBytes", 5.mb.toUnit(DataSizeUnit.Bytes).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 DataSize d ? d.toUnit(DataSizeUnit.Bytes).value : v));
  return out;
}

Type guard

boolean isYamlRenderable(Object v) {
  return !(v instanceof DataSize) && !(v instanceof Duration) && !(v instanceof PClass);
}

Try / catch

try {
  renderer.renderDocument(value);
} catch (RendererException e) {
  if (e.getMessage().startsWith("Values of type `DataSize` cannot be rendered as YAML")) {
    renderer.renderDocument(convertDataSizes(value));
  } else throw e;
}

Prevention

When it happens

Trigger: renderDocument on a tree containing a DataSize property (e.g. `maxSize = 5.mb`), reaching YamlRenderer.visitDataSize.

Common situations: Configs with `1.gib`, `500.kib` byte-size values being exported to YAML; generic value pipelines that don't pre-convert DataSize.

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


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/ef7819dbe228161e. Report an issue: GitHub.