cloudevents / cloudevents/sdk-csharp
Improve error if invalid CloudEvent in Message<string?, byte[]>.ToCloudEvent()
@jskeet is already working on this.
Since Feb 16, 2024.
- Dominant language
- C#
- Stars
- 334
- Forks
- 88
- Avg merge
- 7m
- Merged PRs (30d)
- 2
Description
The extension method to create a CloudEvent from a kafka message currently throws an ArgumentException if the message is not a CloudEvent type event, or if the headers fail validation. This means that you need to interrogate the Exception if you wish to handle this type of poisonous message explicitly.
System.ArgumentException: Unknown CloudEvents spec version '0.1' (Parameter 'message')
at CloudNative.CloudEvents.Kafka.KafkaExtensions.ToCloudEvent(Message2 message, CloudEventFormatter formatter, IEnumerable1 extensionAttributes)
at CloudNative.CloudEvents.Kafka.KafkaExtensions.ToCloudEvent(Message2 message, CloudEventFormatter formatter, CloudEventAttribute[] extensionAttributes)
at JustEat.OpaOrderEventsWorker.Worker.EventConsumer.CloudEventKafkaEventWorker1.ConsumeEvents(CancellationToken cancellationToken) in /_/src/Worker/EventConsumer/CloudEventKafkaEventWorker`1.cs:line 52
I think it would be worthwhile to create a custom Exception and throw this if the message is invalid.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.