-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Improve Handler interface #4844
Comments
I'm generally in favor of these improvements 👍 |
Is there an update to this issue? Would love to see this incorporated into the next breaking release |
@marbar3778, not really. Would like for someone to start taking a stab at this...it'll be a pretty hefty PR from what I can imagine though. |
There is always a way to make this a gentle, non-breaking change.
This lets any new module take advantage of the new interface, and any legacy handlers keep working. Once that is done, the After a few releases, support for the Handler interface can be dropped, and just use MsgHandler. Or course the names above may not be so great, please change them. But the process is a tried and true way of gently upgrading by deprecating but not removing functionality. |
That line of reasoning seems fair at initial glance. Any chance you can take this one @ethanfrey? If not, I can do it. |
I would be happy to start a PR with most of those points. But I prefer not to touch baseapp. I would leave this to you to finish on that PR if that is okay with you:
And of course, actually migrating the modules... I don't volunteer for that. But that is not urgent. this PR would just be to allow the interfaces. |
would recommend moving this into 0.38 milestone, tendermint will be removing cmn.Error in the next major release (0.33), and upgrade TM in the sdk will be blocked on this work or at least moving off cmn.Error |
I would like one sdk release where both the new error format and the old (sdk.Error off cmn.Error) code work. So one can upgrade there without breaking changes, and then migrate the app on that dependency, before making the breaking upgrade. In general, I recommend to leave 1 or 2 releases where new and old versions both work before removing support for the old version, for nice upgradeability for everyone downstream. That said, I will look at making a PR to make the error way usable |
For the record, we already have |
Summary
With #4821, I provided a nice error library with stacktrace support for cosmos-sdk. This addressed #4708 to allow developers to get stack traces on test failures, if they use the new errors.
However, once we hit the Handler interface, we can no longer use the error interface, but rather fit it into a sdk.Result:
type Handler func(ctx Context, msg Msg) Result
. This encourages many functions to returnsdk.Error
, then returnerr.Result()
at the Handler interface. Which discourages use of richer error structs.Problem Definition
Passing a consistent, stacktrace-enriched error class allows much better test-ability at all layers, especially at Handler-level or app-level integration tests. Let's make these errors first class citizens.
I have discussed this with @marbar3778 and he liked these changes. I would like to get more opinion from the other devs. I am happy for feedback here early on, and if you like the goal, but want a smoother migration path, I can provide a proposal for backwards compatibility here as well.
Proposal
I propose a few steps, some breaking, some non-breaking.
Add
sdk.ResultFromError(err error)
. Iferr
implementssdk.Error
, then we call theResult
method on it. If not, then we calltypes/errors.ABCIInfo()
to get the info and generate ansdk.Result
from that. We can standardize on this usage, and allow an incremental migration from existing error packageChange
type Handler func(ctx Context, msg Msg) Result
totype Handler func(ctx Context, msg Msg) (*Result, error)
. And removeCode
andCodespace
fromResult
. Result should only be returned on success, error on failure.runTx
/runMsg
inBaseApp
can construct an ABCIResult properly on success or failure. In practice, this may be done in multiple steps to be less breaking, but should be after v0.36 in any case. (Note that we can still use sdk.Error and just return it without.Result()
as a first step, only changing the error creation piece by piece through the modules that desire it)Advantages:
error
interface not ABCI-likeResult
struct to allow stacktrace info to flow over all levels of the code(*Result error)
design rather than returningsdk.Result
orsdk.Error
down into the Keeper and below.Current:
Proposed:
For Admin Use
The text was updated successfully, but these errors were encountered: