-
Notifications
You must be signed in to change notification settings - Fork 197
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
Custom errors support in FFI contract invocations and queries #1125
Conversation
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
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.
Looks good. Just a couple of minor suggestions, and it looks like we may have some Go build issues to work out. Thanks!
@@ -61,7 +61,7 @@ func TestDiffSwaggerYAML(t *testing.T) { | |||
var existingSwaggerBytes []byte | |||
existingSwaggerBytes, err = os.ReadFile(filepath.Join("..", "..", "docs", "swagger", "swagger.yaml")) | |||
assert.NoError(t, err) | |||
|
|||
fmt.Println(string(b)) |
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'm guessing this was left over from testing something?
if err != nil { | ||
return err | ||
} | ||
options["errors"] = errorsAbi |
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 think this ends up working the way we expect it to, but the intention is that options
is a set of fields passed in by the user.
Maybe invokeContractMethod
should also take in an errors
param as well, instead of piggybacking on the options
map?
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 fact that was the route I took originally but then realized that the errors
as a construct in the interface definition doesn't apply universally to other protocols such as Fabric. So instead of forcing that as part of the plugin API, I decided to use the options so it fits with this being an "optional" feature. But if you feely strongly about this, I can certainly move to making it part of the InvokeContract()
signature out of the options
parameter
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.
upon further discussing this with @nguyer and @peterbroadhurst, I realized that the errors
construct is already part of the standard FFI API because of the earlier work in FFTM: https://github.com/hyperledger/firefly-transaction-manager/blob/main/pkg/ffcapi/api.go#L202. so I'll make the update as suggested above by Nicko
internal/contracts/manager.go
Outdated
if req.Options == nil { | ||
req.Options = map[string]interface{}{ | ||
"errors": errors, | ||
} | ||
} else { | ||
req.Options["errors"] = errors | ||
} |
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.
Perhaps instead of setting req.Options["errors"]
here, we should add an errors
field to the ContractCallRequest
struct itself.
@@ -33,7 +33,7 @@ var ( | |||
MsgWebsocketClientError = ffe("FF10108", "Error received from WebSocket client: %s") | |||
Msg404NotFound = ffe("FF10109", "Not found", 404) | |||
MsgUnknownBlockchainPlugin = ffe("FF10110", "Unknown blockchain plugin: %s") | |||
MsgEthconnectRESTErr = ffe("FF10111", "Error from ethconnect: %s") | |||
MsgEthconnectRESTErr = ffe("FF10111", "Error from ethereum connector: %s") |
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.
Should we also rename the key itself? (not the error code)
@@ -271,4 +271,6 @@ var ( | |||
MsgIdempotencyKeyDuplicateMessage = ffe("FF10430", "Idempotency key '%s' already used for message '%s'", 409) | |||
MsgIdempotencyKeyDuplicateTransaction = ffe("FF10431", "Idempotency key '%s' already used for transaction '%s'", 409) | |||
MsgNonIdempotencyKeyConflictTxInsert = ffe("FF10432", "Conflict on insert of transaction '%s'. No existing transaction matching idempotency key '%s' found", 409) | |||
MsgErrorNameMustBeSet = ffe("FF10433", "Error name must be set", 400) |
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.
Seeing this out of context confused me for a little bit as to the meaning of the message.
I was originally reading it as: Error. Name must be set.
But I realized that's not actually what it says 🙂
Would it make more sense to say: The name of the error must be set
?
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
@nguyer , should be all addressed in the latest commit. I believe the build errors should be taken care of once the dependency components are updated with a new release (and the dependency version in go.mod is updated) |
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Signed-off-by: Jim Zhang <jim.zhang@kaleido.io>
Codecov Report
@@ Coverage Diff @@
## main #1125 +/- ##
==========================================
- Coverage 99.82% 99.33% -0.50%
==========================================
Files 302 303 +1
Lines 19506 19617 +111
==========================================
+ Hits 19472 19486 +14
- Misses 29 122 +93
- Partials 5 9 +4
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
For a test solidity contract that declares custom errors like the following :
Use the
POST /contracts/interfaces/generate
endpoint to generate the corresponding FFI:Then when invoking the generated API:
matching custom error
response:
no matching custom error (raw error data returned):
response:
regular error from the require()
response: