CLI: improve error reporting#659
Merged
imobachgs merged 6 commits intoagama-project:masterfrom Jul 13, 2023
imobachgs:improve-error-reporting
Merged
CLI: improve error reporting#659imobachgs merged 6 commits intoagama-project:masterfrom imobachgs:improve-error-reporting
imobachgs merged 6 commits intoagama-project:masterfrom
imobachgs:improve-error-reporting
Conversation
Contributor
|
Thanks for pointing out Luca Palmieri's Error Handling In Rust - A Deep Dive as a detailed background piece |
This was referenced Jul 13, 2023
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CLI error reporting is rather poor. In some cases, the errors are pretty hard to read (e.g., when it cannot connect to the D-Bus server) and, in other cases, the problem is not properly reported (e.g., when lshw or jsonnet are missing or when the jsonnet invocation fails).
The anyhow crate helps with reporting the problems, including a backtrace if supported. We should make use of its reporting capabilities.
Errors to focus on:
lshw, jsonnet).Solution
Better CLI errors
agama-cliuses now anyhow to report the errors. Let's see some examples:Exit code
agama-clinow returns an exit code which is especially important when using the CLI in scripts. As usual, it returns 0 for success and 1 for errors.Stop using &str as error types
In Rust, anything can be used as an error. Nothing stops you from using, e.g., a string slice (
&str) as your error type. We used this approach when handling settings from the command line. This PR introduces a newSettingsErrorenum instead.Partially get rid of
Box<dyn Error>We have replaced
Box<dyn Error>with concrete error types.Testing