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

Adding protocol.Result to Send and Request client interface. #425

Merged
merged 5 commits into from
Mar 30, 2020

Conversation

n3wscott
Copy link
Member

@n3wscott n3wscott commented Mar 27, 2020

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) or protocol.IsACK(result) to test the non-nil case.

Fixes #422

We now have the hooks for protocols to bubble up any protocol results.

Scott Nichols added 3 commits March 27, 2020 09:22
Signed-off-by: Scott Nichols <snichols@vmware.com>
Signed-off-by: Scott Nichols <snichols@vmware.com>
Signed-off-by: Scott Nichols <snichols@vmware.com>
@n3wscott n3wscott marked this pull request as ready for review March 27, 2020 17:39
resp, err := c.Request(ctx, e)
if err != nil {
log.Printf("failed to send: %v", err)
resp, result := c.Request(ctx, e)
Copy link
Member Author

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.

Copy link
Member Author

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>
Copy link
Member

@slinkydeveloper slinkydeveloper left a 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 {
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?

@@ -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 {
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sure


// 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))
Copy link
Member

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

Copy link
Member Author

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>
@n3wscott n3wscott merged commit f4cf461 into cloudevents:master Mar 30, 2020
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 this pull request may close these issues.

[FR] Surface protocol-specific errors
2 participants