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

  1. Fix the member name spelling/casing on the access site.
  2. Verify the receiver actually defines the property (check the module/class schema).
  3. Use a null-safe access (`obj[key] ?? default` or optional `?.` in host bindings) when the member is genuinely optional.
  4. 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

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


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/be8379de2267fd3f. Report an issue: GitHub.