-
Notifications
You must be signed in to change notification settings - Fork 278
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
Emit central error event from Vorpal #94
Comments
Wouldn't you want to handle the error based on the context of the command? I mean, I can have vorpal emit a global duplicate event of Could you please explain a bit more? Thanks. |
@dthree thanks for the quick response! I'm used (in web apps) to have a global error handler and I think it would be useful for vorpal too:
This way you can have a central place where all error are handled so you can have a standardized handling and don't have to duplicate logic. This error handler should be passed the same context as the command that originated the error so that it could do things like |
You could do something similar by having an function to handle errors and call it like this:
but it would require to wrap all the code in |
Okay I guess I'm okay with this: vorpal.on('error', (error, context) {
// Context would be similar to {command: commandName, args: actionArguments}
// Print an error message and log the error in a separate file or maybe close the app...
}) BTW, when you programmatically execute Vorpal commands, this is already covered: vorpal.exec('foo').then(function (data) {
// didn't error
}).catch(function (err) {
// errored
});
vorpal.exec('foo', function (err, data) {
if (err) {
}
}); |
Would it be possible to have an event that catches all errors so we can respond accordingly?
For example every time I throw an error in
command.validate()
(fyi, it's not documented in the wiki) orcommand.action()
I want to log the error somewhere and output a friendly error message.The text was updated successfully, but these errors were encountered: