You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 themain
function and provide an exit code. However, allerror-stack
errors currently return an exit code of1
.Implementation
A method,
exit_code(&self, code: i32)
or could be namedattach_exit_code(...)
for symmetry, could be added to theReport
struct, or maybe theResultExt
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, anderror-stack
conveniently exposes aResult
alias that's more specific. So I believe just adding this trait implementation over theReport
type would work, and by default, it could return an exit code of1
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.
The text was updated successfully, but these errors were encountered: