{"record":{"id":"e9a486144bf040c9","repo":"apple/pkl","slug":"cannotfindmember-key-on-object","errorCode":null,"errorMessage":"cannotFindMember ${key} on object","messagePattern":"cannotFindMember (.+?) on object","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/binary/SubscriptNode.java","lineNumber":152,"sourceCode":"\n  @Specialization\n  protected long eval(VmBytes receiver, long index) {\n    if (index < 0 || index >= receiver.getLength()) {\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder()\n          .evalError(\"elementIndexOutOfRange\", index, 0, receiver.getLength() - 1)\n          .withProgramValue(\"Value\", receiver)\n          .build();\n    }\n    return receiver.get(index);\n  }\n\n  private Object readMember(VmObject object, Object key, IndirectCallNode callNode) {\n    var result = VmUtils.readMemberOrNull(object, key, callNode);\n    if (result != null) return result;\n\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder().cannotFindMember(object, key).build();\n  }\n}\n","sourceCodeStart":134,"sourceCodeEnd":155,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/binary/SubscriptNode.java#L134-L155","documentation":"Thrown when a subscript/bracket read on a Pkl object does not resolve to any member: the object has no property or element matching the given key. It is Pkl's equivalent of a 'member not found' error for dynamic member reads (`VmUtils.readMemberOrNull` returned null).","triggerScenarios":"Evaluating `obj[key]` or dynamic member read where `key` matches no property of the object; e.g. reading a config field that was never declared, or a typo in the key name.","commonSituations":"Typos in config keys, expecting a property added by an amendment that wasn't applied, reading optional fields without a default, schema drift between producer and consumer of a config.","solutions":["Fix the key name (check the exact spelling in the error)","Declare the property on the object or its class before reading it","Use `obj[key] ?? default` style defaulting where the API allows, or check with `containsKey`-style helpers","Verify the intended amendment/module is actually imported and applied"],"exampleFix":"// before\nport = config[\"prot\"]\n// after\nport = config[\"port\"] ?? 8080","handlingStrategy":"type-guard","validationCode":"// pkl\nexists = obj.hasProperty(\"key\") // or containsKey for mappings\nvalue = if (exists) obj[\"key\"] else default","typeGuard":"function hasMember(obj, key) { return obj != null && key in obj }","tryCatchPattern":"// catch member-not-found and supply a default value","preventionTips":["Validate config keys against the schema","Use defaults for optional properties","Keep producer/consumer schemas in sync"],"tags":["pkl","member-not-found","object"],"backgroundTag":"record-not-found","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}