Right now we are using the todo!()
macro which is great for simulating when our program panics. The error message that we get can be improved upon.
We will look at color-eyre that will allow us to handle the errors we receive to be more visual and human-readable.
The todo!
macro is useful and it also exposes what
happens if our application panics.
thread 'main' panicked at 'not yet implemented', src/main.rs:2:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
This could be both more readable and contain more information while also being colored using color_eyre.
The application panicked (crashed).
Message: not yet implemented
Location: src/main.rs:5
Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
We'll use cargo-edit to add the package to our Cargo.toml.
cargo install cargo-edit
cargo add color_eyre
main
can return Result
, so we'll use color_eyre
's
Result
as our return value and color_eyre::install
to
install the default panic and error reporting hooks.
install
returns a Result
so we can use ?
to handle
any errors if necessary.
We haven't shown off everything that color_eyre is capable of. In addition to panic handling, color_eyre allows us to track additional information in the context of our errors and include suggestions by taking advantage of distributed tracing infrastructure.
We'll see more of how this helps as we build out the CLI.