sdk-go icon indicating copy to clipboard operation
sdk-go copied to clipboard

Nil pointer exception after NewEvent with invalid version.

Open n3wscott opened this issue 3 years ago • 1 comments

If, say,event := cloudevents.NewEvent("2.0") is used to make event and then event.SetType("foo") is called, this causes a nil pointer exception because the internal context is nil.

I would expect to be able to call the convenience methods on event without NPE on an event that the NewEvent method made. I might not expect that event to be sendable by the client. But I do want to assemble it and then look at the validation errors.

n3wscott avatar Apr 08 '21 22:04 n3wscott

QQ: What if NewEvent() would do a validation against a supported set of versions instead? This would require an API change though :/

In general I'd +1 on retrieving a non-nil context and let the validation helpers do their job.

embano1 avatar Jul 14 '21 11:07 embano1