apple/pkl · error · VmException
cannotFindMember
Error message
cannotFindMember
What it means
Generic Pkl member lookup failure: `VmUtils.readMember` calls `readMemberOrNull` and, when the receiver has no member matching `memberKey`, throws a cannotFindMember error including the receiver and key. This is the standard 'undefined property' error for object access.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmUtils.java:310
return Map.of();
}
var files = (VmMapping) filesOrNull;
var result = new LinkedHashMap<String, FileOutput>();
files.forceAndIterateMemberValues(
(key, member, value) -> {
assert member.isEntry();
result.put((String) key, fileOutputFactory.apply((VmTyped) value));
return true;
});
return result;
}
@TruffleBoundary
public static Object readMember(VmObjectLike receiver, Object memberKey) {
var result = readMemberOrNull(receiver, memberKey);
if (result != null) return result;
throw new VmExceptionBuilder().cannotFindMember(receiver, memberKey).build();
}
@TruffleBoundary
public static @Nullable Object readMemberOrNull(
VmObjectLike receiver, Object memberKey, boolean checkType) {
return readMemberOrNull(receiver, memberKey, checkType, IndirectCallNode.getUncached());
}
@TruffleBoundary
public static @Nullable Object readMemberOrNull(
VmObjectLike receiver, Object memberKey, IndirectCallNode callNode) {
return readMemberOrNull(receiver, memberKey, true, callNode);
}
@TruffleBoundary
public static @Nullable Object readMemberOrNull(VmObjectLike receiver, Object memberKey) {
return readMemberOrNull(receiver, memberKey, true, IndirectCallNode.getUncached());
}View on GitHub (pinned to f3efcbfc9b)
Solutions
- Fix the member name spelling/casing on the access site.
- Verify the receiver actually defines the property (check the module/class schema).
- Use a null-safe access (`obj[key] ?? default` or optional `?.` in host bindings) when the member is genuinely optional.
- If reading a Map/List, check the key/index exists before access.
Example fix
// before val port = server.porrt // after val port = server.port
Defensive patterns
Strategy: type-guard
Validate before calling
// prefer null-safe access val v = obj?.key ?? defaultValue
Type guard
function hasMember(obj, key) { return obj != null && key in obj; } Try / catch
try { return obj[key]; } catch (e) { return null; /* member missing */ } Prevention
- Verify property names against the module schema
- Use typed bindings/generated code to catch typos at compile time
- Prefer optional access with defaults for potentially absent members
When it happens
Trigger: Reading `obj.someKey` or `obj["someKey"]` where `obj` (a VmObjectLike: object, module, or class instance) does not define that member and no catch-all/defaulting member exists.
Common situations: Typos in property names, config keys that differ in casing, accessing a property that exists in a newer Pkl stdlib/schema version but not the one in use, subscripting maps with keys that are absent.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- cannotFindMember
- defaultMember/cannotFindMember
- externalMember
- Node `%s` of type `%s` does not have a property named `%s`.
- JavaType token must be parameterized.
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/be8379de2267fd3f.
Report an issue: GitHub.