-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): add opt-in cleanup on failures
- Loading branch information
Showing
4 changed files
with
161 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
use arx::app::App; | ||
use crossterm::style::Stylize; | ||
use miette::Severity; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let app = App::new(); | ||
|
||
if let Err(err) = app.run().await { | ||
let severity = match err.severity().unwrap_or(Severity::Error) { | ||
| Severity::Advice => "Advice:".cyan(), | ||
| Severity::Warning => "Warning:".yellow(), | ||
| Severity::Error => "Error:".red(), | ||
}; | ||
|
||
if err.code().is_some() { | ||
eprintln!("{severity} {err:?}"); | ||
} else { | ||
eprintln!("{severity}\n"); | ||
eprintln!("{err:?}"); | ||
} | ||
|
||
std::process::exit(1); | ||
} | ||
App::new().run().await | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crossterm::style::Stylize; | ||
use miette::Severity; | ||
|
||
/// Prints an error message and exits the program if given an error. | ||
pub fn try_report<T>(fallible: miette::Result<T>) { | ||
if let Err(err) = fallible { | ||
let severity = match err.severity().unwrap_or(Severity::Error) { | ||
| Severity::Advice => "Advice:".cyan(), | ||
| Severity::Warning => "Warning:".yellow(), | ||
| Severity::Error => "Error:".red(), | ||
}; | ||
|
||
if err.code().is_some() { | ||
eprintln!("{severity} {err:?}"); | ||
} else { | ||
eprintln!("{severity}\n"); | ||
eprintln!("{err:?}"); | ||
} | ||
} | ||
} |