-
Notifications
You must be signed in to change notification settings - Fork 224
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
Adding protocol.Result to Send and Request client interface. #425
Conversation
Signed-off-by: Scott Nichols <snichols@vmware.com>
Signed-off-by: Scott Nichols <snichols@vmware.com>
Signed-off-by: Scott Nichols <snichols@vmware.com>
resp, err := c.Request(ctx, e) | ||
if err != nil { | ||
log.Printf("failed to send: %v", err) | ||
resp, result := c.Request(ctx, e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the samples that use client and assume Send/Request throw errors for non nil results need to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added an issue.
Signed-off-by: Scott Nichols <snichols@vmware.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits
README.md
Outdated
// handle result as an accepted event. | ||
} else if cloudevents.IsNACK(result) { | ||
// handle result as a rejected event. | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh why that case should be available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you tried to send bad data it will not NAC nor ACK, it will throw an error
I think the last else should be else if result != nil {
I will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok fine, can you add a comment about it?
v2/client/client.go
Outdated
@@ -138,18 +138,21 @@ func (c *ceClient) Request(ctx context.Context, e event.Event) (*event.Event, er | |||
var resp *event.Event | |||
msg, err := c.requester.Request(ctx, (*binding.EventMessage)(&e)) | |||
defer func() { | |||
if msg == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style comment: IMO it looks cleaner to branch on msg != nil and both schedule the defer and convert the msg to event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh sure
v2/client/client.go
Outdated
|
||
// try to turn msg into an event, it might not work and that is ok. | ||
if rs, err := binding.ToEvent(ctx, msg); err != nil { | ||
cecontext.LoggerFrom(ctx).Debugw("failed calling ToEvent", zap.Error(err), zap.Any("resp", msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is not the expected behaviour. I propose this change:
- If the message is encoding == unknown, then maybe returning an error doesn't make sense (a message with encoding unknown could be just a 202 accepted, so it's not an error from the client POV but just an ack)
- If the message is a known encoding, but there was an error while translating to event, then something is wrong with the event response (invalid event), so the error should be reported back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make a choice on which error to send up for responses.
Signed-off-by: Scott Nichols <snichols@vmware.com>
NOTE: This is a breaking API change. client.Send and client.Receive might return a non-nil result which is an ACK.
use
cloudevents.IsACK(result)
orprotocol.IsACK(result)
to test the non-nil case.Fixes #422
We now have the hooks for protocols to bubble up any protocol results.