Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise a more specific error for incompatible schema from the registry #218

Open
HarlemSquirrel opened this issue Dec 11, 2024 · 2 comments · May be fixed by #219
Open

Raise a more specific error for incompatible schema from the registry #218

HarlemSquirrel opened this issue Dec 11, 2024 · 2 comments · May be fixed by #219

Comments

@HarlemSquirrel
Copy link

Right now, the schema from a Confluent Schema Registry is assumed to be AVRO which is the default. If it is not, we still attempt to parse it and then can get somewhat confusing errors like MultiJson::ParseError for PROTOBUF schema.

It would be nice to throw a more specific error here like

class AvroTurf
  class Messaging
    class IncompatibleSchemaError < StandardError; end
   
    def fetch_schema(subject:, version: 'latest')
      schema_data = registry.subject_version(subject, version)
      schema_id = schema_data.fetch('id')
      schema_type = schema_data["schemaType"]
      if schema_type.present? && schema_type != "AVRO"
        raise IncompatibleSchemaError("The #{schema_type} schema for #{subject} is incompatible.")
      end
      schema = Avro::Schema.parse(schema_data.fetch('schema'))
      [schema, schema_id]
    end
  end
end

For the long-run, it would be awesome to get maybe a new gem that could handle all three schema types that the registry supports: AVRO, PROTOBUF, and JSON. I know it has been brought up before in #158 to reuse some of this gem.

@dasch
Copy link
Owner

dasch commented Dec 12, 2024

Could you whip up a PR for this?

@HarlemSquirrel HarlemSquirrel linked a pull request Dec 13, 2024 that will close this issue
@HarlemSquirrel
Copy link
Author

@dasch just opened #219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants