Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/error-stack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ once_cell = "1.18.0"
supports-color = "2.1.0"
supports-unicode = "2.0.0"
owo-colors = "3.5.0"
thiserror = "1.0.48"

[build-dependencies]
rustc_version = "0.4"
Expand Down
42 changes: 42 additions & 0 deletions libs/error-stack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@
//!
//! # Quick-Start Guide
//!
//! ## In a new project
//!
//! ```rust
//! # #![allow(dead_code)]
//! use error_stack::ResultExt;
//! // using `thiserror` is not neccessary, but convenient
//! use thiserror::Error;
//!
//! // Errors can enumerate variants users care about
//! // but notably don't need to chain source/inner error manually.
//! #[derive(Error, Debug)]
//! enum AppError {
//! #[error("serious app error: {consequences}")]
//! Serious { consequences: &'static str },
//! #[error("trivial app error")]
//! Trivial,
//! }
//!
//! type AppResult<T> = error_stack::Result<T, AppError>;
//!
//! // Errors can also be a plain `struct`, somewhat like in `anyhow`.
//! #[derive(Error, Debug)]
//! #[error("logic error")]
//! struct LogicError;
//!
//! type LogicResult<T> = error_stack::Result<T, LogicError>;
//!
//! fn do_logic() -> LogicResult<()> {
//! Ok(())
//! }
//!
//! fn main() -> AppResult<()> {
//! // `error-stack` requires developer to properly handle
//! // changing error contexts
//! do_logic().change_context(AppError::Serious {
//! consequences: "math no longer works",
//! })?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Where to use a Report
//!
//! [`Report`] has been designed to be used as the [`Err`] variant of a `Result`. This crate
Expand Down