apple/pkl · error · VmException

cannotResolveTypeForProtobuf

cannotResolveTypeForProtobuf

Error message

cannotResolveTypeForProtobuf

What it means

The Protobuf renderer could not determine the Pkl class of the value it is rendering — the resolved class came back null. Protobuf output requires a concrete type name to compute the protobuf message type, so rendering aborts.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/stdlib/protobuf/RendererNodes.java:123

    }
  }

  public abstract static class renderType extends ExternalMethod1Node {
    @SuppressWarnings("unused")
    @Specialization
    protected String eval(VmTyped self, Object value) {
      return renderType(value);
    }
  }

  @TruffleBoundary
  private static String renderType(Object value) {
    var clazz =
        value instanceof VmValue vmValue
            ? vmValue.getVmClass()
            : value instanceof TypeNode typeNode ? typeNode.getVmClass() : value.getClass();
    if (clazz == null) {
      throw new VmExceptionBuilder()
          .evalError("cannotResolveTypeForProtobuf")
          .withProgramValue("Value", value)
          .build();
    }
    var name =
        clazz instanceof VmClass vmClass
            ? vmClass.getSimpleName()
            : ((Class<?>) clazz).getSimpleName();

    return fieldNameEscaper.escape(name);
  }

  @TruffleBoundary
  private static ProtobufRenderer createRenderer(VmTyped self, StringBuilder builder) {
    var indent = (String) VmUtils.readMember(self, Identifier.INDENT);

    return new ProtobufRenderer(builder, indent, PklConverter.fromRenderer(self));
  }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Render a concrete typed object or Dynamic instance whose class is resolvable
  2. Check that the type being referenced actually exists/imports correctly in the module
  3. Use a different output format for values without concrete Pkl classes
Defensive patterns

Strategy: validation

Validate before calling

function hasResolvableClass(v) { return v != null && resolveVmClass(v) != null; }

Type guard

const isProtobufRenderableValue = (v) => getVmClass(v) != null;

Try / catch

try { renderAsProtobuf(value) } catch (e) { if (e.code === 'cannotResolveTypeForProtobuf') { /* check type references/imports */ } else throw e }

Prevention

When it happens

Trigger: Calling the protobuf render entry point (`eval`) on a value whose class cannot be resolved: a VmValue/VmValue holder or TypeNode whose `getVmClass()` returns null, or an object with no concrete class.

Common situations: Rendering a null-class placeholder or synthetic value to protobuf; passing a type reference (TypeNode) that points at a class that failed to load or is undefined.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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