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

Add ability to display stacktraces from unhandled exceptions #166

Closed
1 task done
jhorbulyk opened this issue Jan 21, 2020 · 1 comment · Fixed by #168
Closed
1 task done

Add ability to display stacktraces from unhandled exceptions #166

jhorbulyk opened this issue Jan 21, 2020 · 1 comment · Fixed by #168

Comments

@jhorbulyk
Copy link
Contributor

Is your feature request related to a problem? Please describe.
When the code inside of a command throws an exception that is not caught caporal prints the message of the exception that is thrown and has the process exit with code 2. When this thrown exception is the result of bad inputs or failures to access resources (e.g. internet, files, etc), this behavior is OK. However, when an exception is thrown because of poor programming logic on the part of the command author, it's very difficult to diagnose what has happened, expectially when the exception is thrown by dependency libraries or node built-ins. It would be nice if there was some way that the stack trace could be rendered to fix those cases.

Describe the solution you'd like
When the verbose flag is set and an unhandled exception is thrown from inside a command, print out the full stack trace of the exception in addition to the exception's message. When the verbose flag is not set, continue to only print out the exception's message.

Describe alternatives you've considered
Adding another flag or environment variable to toggle this behavior is an option, but extending existing flags is probably more desirable.

Additional context
The documentation so far doesn't really lay out best practices for errors and exceptions.

Would you be able to work on it and provide a pull request ?

  • Yes
@johnwebbcole
Copy link

I've been modifying my node_modules/caporal/lib/program.js line 90 https://github.com/mattallty/Caporal.js/blob/master/lib/program.js#L90 with

this.logger().error("\n" + errObj.message + "\n" + errObj.stack);

This shows the stack trace. It would be nice to have an option to show this :-)

J

jhorbulyk added a commit to elasticio/Caporal.js that referenced this issue Feb 17, 2020
If the -v / --version flag is set and an unhandled error is thrown, the stacktract of that error
will be rendered.  Fixed some bugs related to some unhandled exceptions not being handled correctly.

Fixes mattallty#166
jhorbulyk added a commit to elasticio/Caporal.js that referenced this issue Feb 17, 2020
If the -v / --version flag is set and an unhandled error is thrown, the stacktract of that error
will be rendered.  Fixed some bugs related to some unhandled exceptions not being handled correctly.
Add .idea to .gitignore.

Fixes mattallty#166
jhorbulyk added a commit to elasticio/Caporal.js that referenced this issue Feb 17, 2020
If the -v / --version flag is set and an unhandled error is thrown, the stacktract of that error
will be rendered.  Fixed some bugs related to some unhandled exceptions not being handled correctly.
Add .idea to .gitignore.

Fixes mattallty#166
jhorbulyk added a commit to elasticio/Caporal.js that referenced this issue Feb 17, 2020
If the -v / --verbose flag is set and an unhandled error is thrown, the stacktract of that error
will be rendered.  Fixed some bugs related to some unhandled exceptions not being handled correctly.
Add .idea to .gitignore.

Fixes mattallty#166
mattallty pushed a commit that referenced this issue May 4, 2020
)

If the -v / --verbose flag is set and an unhandled error is thrown, the stacktract of that error
will be rendered.  Fixed some bugs related to some unhandled exceptions not being handled correctly.

Fixes #166
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.

2 participants