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

Ability to return meta information when aborting from the 'before' hook #48

Closed
achambers opened this issue May 28, 2014 · 4 comments
Closed
Milestone

Comments

@achambers
Copy link

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.

Thoughts?

/cc @mholt

@mholt
Copy link
Owner

mholt commented May 28, 2014

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?

@mholt mholt added this to the 3.0 milestone May 28, 2014
@mholt
Copy link
Owner

mholt commented Jul 11, 2014

@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.

Sound good?

@mholt
Copy link
Owner

mholt commented Jul 13, 2014

Closing unless this still needs attention. Thanks again for the feedback!

@mholt mholt closed this as completed Jul 13, 2014
@achambers
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants