{"record":{"id":"bf7d78dafade4c30","repo":"apple/pkl","slug":"cannotfindpropertyinobject-bf7d78","errorCode":"cannotFindPropertyInObject","errorMessage":"Cannot find property `{0}` in object of type `{1}`.","messagePattern":"Cannot find property `(.+?)` in object of type `(.+?)`\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/member/ReadPropertyNode.java","lineNumber":116,"sourceCode":"    }\n  }\n\n  // This method effectively covers `VmObject receiver` but is implemented in a more\n  // efficient way. See:\n  // https://www.graalvm.org/22.0/graalvm-as-a-platform/language-implementation-framework/TruffleLibraries/#strategy-2-java-interfaces\n  @Specialization(guards = \"receiver.getClass() == cachedClass\", limit = \"99\")\n  protected Object evalObject(\n      Object receiver,\n      @Cached(\"getVmObjectSubclassOrNull(receiver)\") Class<? extends VmObjectLike> cachedClass,\n      @Cached(\"create()\") IndirectCallNode callNode) {\n\n    var object = cachedClass.cast(receiver);\n    checkConst(object);\n    var result = VmUtils.readMemberOrNull(object, propertyName, true, callNode);\n    if (result != null) return result;\n\n    CompilerDirectives.transferToInterpreter();\n    throw cannotFindProperty(object);\n  }\n\n  // specializations for all other types\n  @Specialization(guards = \"receiver.getClass() == cachedClass\", limit = \"99\")\n  protected Object evalOther(\n      Object receiver,\n      @Cached(\"receiver.getClass()\") @SuppressWarnings(\"unused\") Class<?> cachedClass,\n      @Cached(\"resolveProperty(receiver)\") ClassProperty resolvedProperty,\n      @Cached(\"createCallNode(resolvedProperty)\") DirectCallNode callNode) {\n\n    return callNode.call(receiver, resolvedProperty.getOwner(), resolvedProperty.getName());\n  }\n\n  protected static @Nullable Class<? extends VmObjectLike> getVmObjectSubclassOrNull(Object value) {\n    // OK to perform slow cast here (not a guard)\n    return value instanceof VmObjectLike objectLike ? objectLike.getClass() : null;\n  }\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/member/ReadPropertyNode.java#L98-L134","documentation":"Thrown when a property access `receiver.prop` on a Pkl object (VmObjectLike) finds no member named `prop`, even when walking default and external members (`readMemberOrNull` with forceLookup). After const-checking the receiver, `evalObject` attempts the member read; a null result means the property is absent from the object's class chain, so Pkl raises 'cannot find property' against the object. This is the standard dynamic property-miss error for object receivers.","triggerScenarios":"Occurs when evaluating `obj.propName` where `obj` is a Pkl object/module and no property `propName` is declared on it or any of its supertypes — e.g. accessing an undefined field on an amending object, a module-level property that was never defined, or a property removed from a stdlib/dependency class.","commonSituations":"Typos in property names in config files; expecting a base class property to be inherited when it is defined only on a sibling class; upgrading a package whose classes dropped or renamed properties; accessing output/stdlib properties that moved between Pkl versions; reading a property on an object literal that only defines different keys.","solutions":["Fix the property name in the read site (check spelling and the object's actual definition).","Add the missing property to the object being read (define it in the class or amend the object).","Use a safe access pattern (`obj[\"prop\"]` with existence check, or `if (\"prop\" in obj)`) when the property may be absent.","Pin or update the dependency package version so the class still declares the expected property."],"exampleFix":"// before\nserver {\n  host = \"localhost\"\n}\nval url = server.protocol + \"://\" + server.host // error: no property `protocol`\n\n// after\nserver {\n  host = \"localhost\"\n  protocol = \"https\"\n}\nval url = server.protocol + \"://\" + server.host","handlingStrategy":"validation","validationCode":"// Pkl: guard dynamic property reads on objects\nfunction readOrNull(obj: Object, key: String): any? =\n  if (key in obj) obj[key] else null","typeGuard":"// Pkl: narrow object shape before member access\nfunction isServerConfig(obj: Object): Boolean =\n  \"host\" in obj && \"port\" in obj","tryCatchPattern":"// Host-side (Java) embedders: catch the evaluation exception and match the error code\ntry {\n  evaluator.evaluateOutput(moduleSource)\n} catch (e: PklBugException | EvaluationException e) {\n  if (e.getMessage().contains(\"Cannot find property\")) {\n    // supply default or surface a friendly message\n  }\n}","preventionTips":["Declare all consumed properties in the class definition; treat object literals as typed shapes.","Pin dependency package versions and review their changelogs for removed/renamed properties.","Use Amends-style base modules so expected properties always exist with defaults.","Evaluate configs in CI to catch missing-property reads before deployment."],"tags":["pkl","property-not-found","member-lookup","object"],"backgroundTag":"resource-not-found","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"}