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

Error helper #4

Closed
sindresorhus opened this issue Jun 18, 2015 · 10 comments
Closed

Error helper #4

sindresorhus opened this issue Jun 18, 2015 · 10 comments

Comments

@sindresorhus
Copy link
Owner

Most of my CLI's have this:

var cli = meow();

fn(function (err) {
    if (err) {
        console.error(err.message);
        process.exit(1);
    }
});

Wonder if we could abstract out the error handling.

Eg:

var cli = meow();

fn('unicorn', function (err) {
    cli.handleError(err);
});

It could potentially also handle showing the stack when --verbose is passed.

Thoughts?

// @kevva @floatdrop @arthurvr @shinnn

@arthurvr
Copy link

Yes please! 👍

@kevva
Copy link
Contributor

kevva commented Jun 19, 2015

Yeah, sure, that'd be useful I think. I'm using the same pattern everywhere in my CLIs too.

@sindresorhus
Copy link
Owner Author

How about the verbose thing?

@gillstrom
Copy link

How do we change the process.exit code for errors?

@sindresorhus
Copy link
Owner Author

Maybe cli.exitCode = 3; and it will use that instead?

Could also be a second argument to cli.handleError(err, exitCode);, but then you wouldn't be able to:

fn('unicorn', cli.handleError(err));

@kevva
Copy link
Contributor

kevva commented Jul 7, 2015

Hmm, why wouldn't that work?

@sindresorhus
Copy link
Owner Author

Oops, should have been:

fn('unicorn', cli.handleError);

Might not be a problem though. Since you can just wrap it in a function, and arrow functions will make that nicer.

@kevva
Copy link
Contributor

kevva commented Jul 7, 2015

Yeah, exactly, shouldn't be that big of a deal. Better future compatibility too if we wanted to add even more stuff.

@LinusU
Copy link

LinusU commented Aug 5, 2015

err.exitCode? That's what express is doing

var err = new Error('Output file exists')
err.exitCode = 9
err.code = 'EEXISTS'
cli.handleError(err)

@sindresorhus
Copy link
Owner Author

Skipping this as we now handle promise errors automagically and I'm not going to continue using callback-style interface.

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

Successfully merging a pull request may close this issue.

5 participants