Crates.io | rich_err |
lib.rs | rich_err |
version | 0.1.4 |
source | src |
created_at | 2024-10-31 12:52:07.272295 |
updated_at | 2024-11-10 11:18:25.383956 |
description | A Rust library for rich, contextual error reporting. |
homepage | |
repository | https://github.com/bensatlantik/rich_err |
max_upload_size | |
id | 1429973 |
size | 5,664 |
This repository was a gift from me to the Rust and open-source community. It is no longer actively maintained and has been archived. Feel free to fork and continue development on your own.
rich_err is a Rust library designed to simplify and enrich error handling by adding structured and meaningful context to errors. It provides a developer-friendly API for consistent and detailed error reporting, making debugging and error analysis more efficient.
To include rich_err
in your project, add the following line to your Cargo.toml
:
[dependencies]
rich_err = "0.1.0"
Here's a basic example demonstrating how to use rich_err:
use rich_err::RichError;
fn main() {
let error = RichError::new("An error occurred")
.with_context("Failed to open file")
.with_context("Permission denied");
println!("{}", error.to_string_with_context());
}
An error occurred Context: Failed to open file Context: Permission denied
RichError new(message: &str) -> Self: Creates a new RichError with a base error message. with_context(mut self, context: &str) -> Self: Adds additional context to the error. to_string_with_context(&self) -> String: Formats the error message with all context included.
Run the tests and ensure everything is working correctly, using the following command:
cargo test
Contributions are welcome! If you'd like to help improve rich_err, feel free to submit issues or pull requests on GitHub.
Fork the repository. Create a new feature branch: git checkout -b feature/your-feature-name. Commit your changes: git commit -m 'Add your feature'. Push to the branch: git push origin feature/your-feature-name. Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
Ben Santora