-
Notifications
You must be signed in to change notification settings - Fork 158
refactor: Added protocol callback error handling #393
Conversation
Codecov Report
@@ Coverage Diff @@
## master #393 +/- ##
==========================================
+ Coverage 89.63% 89.69% +0.05%
==========================================
Files 56 56
Lines 3271 3289 +18
==========================================
+ Hits 2932 2950 +18
Misses 183 183
Partials 156 156
Continue to review full report at Codecov.
|
@soluchok normal semantic PR prefixes: https://github.com/commitizen/conventional-commit-types/blob/v2.2.0/index.json (from https://github.com/probot/semantic-pull-requests) ie refactor not refactoring |
msg := &dispatcher.DIDCommCallback{} | ||
err = msg.Done(dispatcher.Result{Err: err}) | ||
require.NoError(t, err) | ||
e.Callback(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.
Can you please add a test case to validate the error from callback processing ? i.e, consumer calls the callback and validates the error from the callback.
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.
Done, I've modified the existing one
https://github.com/hyperledger/aries-framework-go/pull/393/files#diff-36ac39bebf32030fd7dff6f12aea8d7eR797
@rolsonquadras @soluchok "feat: Added error handling" will be a meaningless entry in the change log. |
Ok, let's decide is it |
My bad, missed @troyronda 's comment. |
This PR may need a discussion. I chatted with @rolsonquadras about the approach and he plans to write something up. Briefly my thoughts were:
|
The current consumer code looks something like follows without error handling (master branch).
With the error handling code added in this PR, the consumer code will look like below.
This would block the main select(actionCh) and other actionEvents will buffer. This would be similar to sync call err := e.Continue().
This has been handled through #436 and #437.
|
|
Consumer will either invoke either Continue() or Stop(). For Stop(), consumer won't send back the error received from the callback. It's the error from action processing. |
pkg/didcomm/dispatcher/api.go
Outdated
// DIDCommAction message type to pass events in go channels. | ||
type DIDCommAction struct { | ||
// DIDComm message | ||
Message DIDCommMsg | ||
// Continue function to be called by the consumer for further processing the message. | ||
Continue func() | ||
Continue func(chan<- ActionError) |
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.
It would be nice if we could avoid having to pas a nil argument when the caller doesn’t care about the error chan. I wonder if we should use a variadic pattern?
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.
Done!
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.
In my opinion, better to pass a clear argument, it's much easier to work with it. But options are not a bad approach, especially for callback (probably it will require one more option in the future)
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 like Rolson's snippet towards the end of this comment better. It would be simpler from a user perspective if the error message has a Retry()
function or something similar.
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.
It has res.Action.Continue()
if you need retry it
e.Continue(eChan) | ||
select { | ||
case res := <-eChan: | ||
require.EqualError(t, res.Err, "document for the id doesn't exists in the database: data not found") |
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.
it would be good to have a test case showing correlation.
Signed-off-by: Andrii Soluk <isoluchok@gmail.com>
Closes: #242
Signed-off-by: Andrii Soluk isoluchok@gmail.com