narrate
This library provides CLI application error and status reporting utilities. The coloured output formatting aims to be similar to Cargo. Error type is a wrapper around Anyhow.
Features
- User facing status messages and error reporting
- Wrap any error with additional context
- Optional help messages for errors
- Set of standard CLI errors with exit codes conforming to sysexits.h
- Convenience
Resulttype - Drop in replacement for Anyhow
How to use
-
Use
narrate::Result<T>as a return type of any fallible function.Within the function, use
?to propagate any error that implements thestd::error::Errortrait. Same asanyhow::Result<T>.use Result; -
Wrap an error with more context by importing the
narrate::ErrorWraptrait. Similar toanyhow::Context, this can give your users more information as to why an error happened.use ;error: project directory already exists cause: Is a directory (os error 20) Try using cargo init -
Use the
narrate::ExitCodetrait to get the sysexits.h conforming exit code from anarrate::Error. By default this is just70 (software error)but it can be easily implemented for any type. -
narrate::CliErrorcollection of typical command line errors. Use them to add context to deeper application errors. Use theirexit_codeto conform to sysexits.h.use ; -
Report errors to the command line with either
report::errorreport::err_fullfor the complete error chain.use ;
-
Report application status to the command line with
report::status. Modeled on the output from Cargo.use Color; use report;
License
narrate is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.