apple/pkl · error · VmException
cannotExportValue
cannotExportValue
Error message
cannotExportValue
What it means
Thrown when a Pkl IntSeq value (a range expression like `1...5` produced as an internal VmIntSeq) is exported to a host-language value. IntSeq is an internal representation that has no host equivalent export, so `export()` unconditionally raises cannotExportValue. Developers hit it when trying to pull such a value out of an evaluation result via the Java API.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmIntSeq.java:67
return step > 0 ? start > last : start < last;
}
public long getLength() {
if (isEmpty()) return 0;
return (Math.abs((end - start) / step)) + 1;
}
@Override
public VmClass getVmClass() {
return BaseModule.getIntSeqClass();
}
@Override
public void force(boolean allowUndefinedValues) {}
@Override
public Object export() {
throw new VmExceptionBuilder().evalError("cannotExportValue", getVmClass()).build();
}
@Override
public void accept(VmValueVisitor visitor) {
visitor.visitIntSeq(this);
}
@Override
public <T> T accept(VmValueConverter<T> converter, Iterable<Object> path) {
return converter.convertIntSeq(this, path);
}
@Override
public PrimitiveIterator.OfLong iterator() {
return new PrimitiveIterator.OfLong() {
boolean hasNext = !isEmpty();
long next = hasNext ? start : last;
View on GitHub (pinned to f3efcbfc9b)
Solutions
- Convert the range to a concrete value in Pkl before exporting: `myProp = (1...5).toList()`.
- On the host side, avoid exporting raw ranges; only export Lists, Mappings, and primitives.
- If you control the schema, change the property type to `List<Int>`.
- Intercept in host code and detect IntSeq-shaped results, rendering them yourself.
Example fix
// Pkl before foo = 1...5 // Pkl after foo = (1...5).toList()
Defensive patterns
Strategy: validation
Validate before calling
// Pkl-side guard assert foo is List<Int> // ensure the property is a concrete List before export
Try / catch
try {
Object v = result.get("foo");
} catch (EvalException e) {
if (e.getMessage().contains("cannotExportValue")) {
// property is an internal value (e.g. IntSeq); fix the Pkl side
}
} Prevention
- Convert ranges with .toList() inside Pkl before exporting.
- Give exported properties explicit concrete types (List, Mapping, primitives).
- Add `... is List<Int>` assertions in Pkl for exported properties.
- Never export intermediate/internal values from your module API surface.
When it happens
Trigger: Calling EvalResult.get() / export on a property whose value is an internal IntSeq (range) object instead of a rendered List.
Common situations: Binding code that reads a Pkl property defined as a range expression; host code expecting a list/array but the range was never converted (e.g. via .toList()) inside Pkl.
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
- Error converting property `%s` in Pkl object of type `%s` to
- The top-level value of a YAML stream must have type `Collect
- type constraint mismatch
- type mismatch
- type mismatch (Nothing type)
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/1ad15765d07c7371.
Report an issue: GitHub.