apple/pkl · error
${getValidationErrorKey()}
Error message
${getValidationErrorKey()} What it means
Raised during type-alias validation in `ValidatingObjectSlotTypeNode.validate()`: when a type-checking node detects a constraint violation (a non-null "violating node"), it throws an evaluation error whose message key comes from `getValidationErrorKey()` (e.g. expected-constraint, expected-type). The stack frames are built from the violating node's location, so the error points at the member that failed validation.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java:3334
protected PType doExport() {
return new PType.Class(BaseModule.getClassClass().export(), typeNode.doExport());
}
}
public abstract static class ValidatingObjectSlotTypeNode extends ObjectSlotTypeNode {
protected ValidatingObjectSlotTypeNode(SourceSection sourceSection) {
super(sourceSection);
}
protected abstract String getValidationErrorKey();
protected abstract @Nullable Node getViolatingNode();
protected final void validate() {
var violation = getViolatingNode();
if (violation == null) return;
throw exceptionBuilder()
.evalError(getValidationErrorKey())
.withLeadingStackFrames(buildLeadingFrames(violation, getSourceSection(), null))
.build();
}
public final void validate(TypeAliasTypeNode outermostAliasNode) {
var violation = getViolatingNode();
if (violation == null) return;
throw exceptionBuilder()
.withLocation(outermostAliasNode)
.evalError(getValidationErrorKey())
.withLeadingStackFrames(
buildLeadingFrames(
violation,
outermostAliasNode.getSourceSection(),
outermostAliasNode.getTypeAlias()))
.build();View on GitHub (pinned to f3efcbfc9b)
Solutions
- Read the reported validation key and stack frames to find the exact member that violated the alias constraint.
- Fix the value so it satisfies the alias's predicate (e.g. bring an Int within the constrained range).
- Relax the type alias definition if the constraint is legitimately too strict for your use case.
- If the alias is from a third-party package, check its documentation for the expected value shape.
Example fix
// before port: Port = 70000 // fails Port = Int(isBetween(0, 65535)) // after port: Port = 8080
Defensive patterns
Strategy: validation
Validate before calling
function checkPort(p) {
if (!Number.isInteger(p) || p < 0 || p > 65535) throw new Error(`not a valid Port: ${p}`);
} Type guard
function isPort(v) { return Number.isInteger(v) && v >= 0 && v <= 65535; } Try / catch
try {
validateAliasConstraints(cfg);
} catch (e) {
// report member that violated the type alias
} Prevention
- Test values against alias predicates with pkl.test.
- Keep alias constraints documented next to their definitions.
- Validate user-supplied inputs before mapping them into typed slots.
When it happens
Trigger: Validating a type-alias-constrained member whose violation node is non-null and which is not nested inside an outer type-alias validation (the plain `validate()` path). Occurs when a value fails an `amends`/`is` constraint or expected type declared by the type alias during object slot validation.
Common situations: Using a type alias like `port: Port` (where `Port = Int(isBetween(0, 65535))`) with an out-of-range value; aliases that constrain object shape (`amends`) receiving objects missing required members.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Values of type `TypeAlias` cannot be rendered as Properties.
- expectedNonEmptyCollection
- expectedSingleElementCollection
- invalidRegexSyntax
- invalidSettingsFile
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/6e91b60e96902f91.
Report an issue: GitHub.