Skip to content

ProtobufDeserializer fails with type_name ... not found for file-level enums #455

@mikelese

Description

Description

ProtobufDeserializer fails to parse protobuf schemas that contain enums defined at the file/package level (outside of any message). The error is:

invalid FieldDescriptorProto: type_name MyEnum not found

Schemas with the same enum nested inside a message deserialize correctly.

Environment

  • @confluentinc/schemaregistry: 1.8.0
  • Node: 22.15.0
  • OS: macOS (darwin arm64)

Minimal reproduction

Works — enum nested inside a message:

syntax = "proto3";
package test;

message MyMessage {
  enum MyEnum {
    MY_ENUM_UNSPECIFIED = 0;
    MY_ENUM_FOO = 1;
  }
  optional MyEnum my_field = 1;
}

Fails — enum at file level (valid proto3):

syntax = "proto3";
package test;

message MyMessage {
  optional MyEnum my_field = 1;
}

enum MyEnum {
  MY_ENUM_UNSPECIFIED = 0;
  MY_ENUM_FOO = 1;
}
import { SchemaRegistryClient } from '@confluentinc/schemaregistry';
import { ProtobufDeserializer } from '@confluentinc/schemaregistry/serde/protobuf';

const client = new SchemaRegistryClient({
  baseURLs: ['http://localhost:8081'],
  basicAuthCredentials: { credentialsSource: 'USER_INFO', userInfo: 'user:pass' },
});
const deserializer = new ProtobufDeserializer(client, 1 /* VALUE */, {});

// Register the "fails" schema above, obtain its schema ID, then:
const buf = Buffer.alloc(6);
buf[0] = 0x00;                 // magic byte
buf.writeInt32BE(schemaId, 1); // schema ID
buf[5] = 0x00;                 // message index (first type)

await deserializer.deserialize('my-topic', buf);
// => throws: invalid FieldDescriptorProto: type_name MyEnum not found

Expected behavior

File-level enums are valid proto3 and commonly used when an enum is shared across multiple messages in the same file. The deserializer should resolve the type reference correctly regardless of whether the enum is defined inside or outside a message.

Impact

This blocks deserialization of any protobuf topic whose registered schema defines enums at the file level. This is a common pattern in production proto files — particularly in multi-message schemas where enums are shared across message types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions