You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just wondering if it would make sense to be able to return some meta information, when aborting the process from the before hook, that will be passed in to the error hook.
I guess the reason I am asking is that I am doing a couple of checks in the before hook and if I abort I want to be able to differentiate between the reasons why the process was aborted. Currently, when you return false from the before hook you simply have an error object with a name property of AbortError. But there is no way to differentiate what it was that caused the error.
Is it possible, and does it make sense, to be able to pass some more information along with aborting the process? Maybe return an error object or something instead of false.
I'll definitely consider this for version 3.0 which is well under way, because I think it could be really useful. In the mean time, how about using a variable defined in a scope that both hooks can access?
@achambers I'm implementing this feature tonight. I'm thinking that the before hook will work a little differently than it does now. Right now, you can return a variety of things: an object to redefine the config, "skip" to skip, false to abort, and nothing (undefined) to continue. I'm going to standardize it so that if you do return anything, you always return an object that can look like this:
{action: "abort",reason: "some reason",config: {/* custom config for just this file */}}
Each property is optional. Not returning anything or not specifying an action or specifying an action of "continue" will carry on as normal. The action can also be "abort" or "skip". Only an action of "abort" will raise an error, but the reason will be carried into the error handler (which I'm still figuring out). If you want to adjust the config for a certain file, you can specify it in the config property.
Sorry @mholt. Didn't get around to replying. Yep, that sounds like a reasonable solution. I'll work it in to what I have when you're done and will see how it feels.
Nice work mate.
Just wondering if it would make sense to be able to return some meta information, when aborting the process from the
before
hook, that will be passed in to theerror
hook.I guess the reason I am asking is that I am doing a couple of checks in the
before
hook and if I abort I want to be able to differentiate between the reasons why the process was aborted. Currently, when you returnfalse
from thebefore
hook you simply have an error object with a name property of AbortError. But there is no way to differentiate what it was that caused the error.Is it possible, and does it make sense, to be able to pass some more information along with aborting the process? Maybe return an error object or something instead of false.
Thoughts?
/cc @mholt
The text was updated successfully, but these errors were encountered: