{"record":{"id":"6e91b60e96902f91","repo":"apple/pkl","slug":"getvalidationerrorkey","errorCode":null,"errorMessage":"${getValidationErrorKey()}","messagePattern":"\\$\\{getValidationErrorKey\\(\\)\\}","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":3334,"sourceCode":"    protected PType doExport() {\n      return new PType.Class(BaseModule.getClassClass().export(), typeNode.doExport());\n    }\n  }\n\n  public abstract static class ValidatingObjectSlotTypeNode extends ObjectSlotTypeNode {\n\n    protected ValidatingObjectSlotTypeNode(SourceSection sourceSection) {\n      super(sourceSection);\n    }\n\n    protected abstract String getValidationErrorKey();\n\n    protected abstract @Nullable Node getViolatingNode();\n\n    protected final void validate() {\n      var violation = getViolatingNode();\n      if (violation == null) return;\n      throw exceptionBuilder()\n          .evalError(getValidationErrorKey())\n          .withLeadingStackFrames(buildLeadingFrames(violation, getSourceSection(), null))\n          .build();\n    }\n\n    public final void validate(TypeAliasTypeNode outermostAliasNode) {\n      var violation = getViolatingNode();\n      if (violation == null) return;\n\n      throw exceptionBuilder()\n          .withLocation(outermostAliasNode)\n          .evalError(getValidationErrorKey())\n          .withLeadingStackFrames(\n              buildLeadingFrames(\n                  violation,\n                  outermostAliasNode.getSourceSection(),\n                  outermostAliasNode.getTypeAlias()))\n          .build();","sourceCodeStart":3316,"sourceCodeEnd":3352,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L3316-L3352","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nport: Port = 70000  // fails Port = Int(isBetween(0, 65535))\n// after\nport: Port = 8080","handlingStrategy":"validation","validationCode":"function checkPort(p) {\n  if (!Number.isInteger(p) || p < 0 || p > 65535) throw new Error(`not a valid Port: ${p}`);\n}","typeGuard":"function isPort(v) { return Number.isInteger(v) && v >= 0 && v <= 65535; }","tryCatchPattern":"try {\n  validateAliasConstraints(cfg);\n} catch (e) {\n  // report member that violated the type alias\n}","preventionTips":["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."],"tags":["pkl","type-alias","validation","constraint"],"backgroundTag":"schema-validation-failed","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}