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-stack: custom exit codes #670

Closed
gluax opened this issue Jun 19, 2022 · 1 comment · Fixed by #671
Closed

error-stack: custom exit codes #670

gluax opened this issue Jun 19, 2022 · 1 comment · Fixed by #671
Assignees
Labels
area/libs > error-stack Affects the `error-stack` crate (library)

Comments

@gluax
Copy link
Contributor

gluax commented Jun 19, 2022

Feature

I think a great feature to add to the error-stack library would be a method on the report that lets you change the exit code.

Motivation

Depending on the type of application you are writing, an exit code can give a lot of information to the user.

By default, Result types can be returned from the main function and provide an exit code. However, all error-stack errors currently return an exit code of 1.

Implementation

A method, exit_code(&self, code: i32) or could be named attach_exit_code(...) for symmetry, could be added to the Report struct, or maybe the ResultExt trait might be a better place for it.

The following steps would be to use Rust's Termination trait. This method is already implemented on the Result type by default, and error-stack conveniently exposes a Result alias that's more specific. So I believe just adding this trait implementation over the Report type would work, and by default, it could return an exit code of 1 as it currently does. This default behavior also aligns with Rust's errors.

If the idea seems beneficial to the crate, I'd be willing to take a stab at this and open a PR.

@TimDiekmann
Copy link
Member

Hi @gluax and thanks for filing this!

I added a few comments to your linked PR 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > error-stack Affects the `error-stack` crate (library)
Development

Successfully merging a pull request may close this issue.

3 participants