Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shepmaster/snafu
Easily assign underlying errors into domain-specific errors while adding context
https://github.com/shepmaster/snafu
error-handling rust
Last synced: 3 days ago
JSON representation
Easily assign underlying errors into domain-specific errors while adding context
- Host: GitHub
- URL: https://github.com/shepmaster/snafu
- Owner: shepmaster
- License: apache-2.0
- Created: 2019-01-27T15:56:35.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-11-19T17:21:04.000Z (about 1 month ago)
- Last Synced: 2024-12-17T08:52:01.794Z (10 days ago)
- Topics: error-handling, rust
- Language: Rust
- Homepage: https://docs.rs/snafu/
- Size: 958 KB
- Stars: 1,464
- Watchers: 18
- Forks: 61
- Open Issues: 82
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# SNAFU
**S**ituation **N**ormal: **A**ll **F**ouled **U**p
[![crates.io][Crate Logo]][Crate]
[![Documentation][Doc Logo]][Doc]
[![Build Status][CI Logo]][CI]SNAFU is a library to easily assign underlying errors into
domain-specific errors while adding context.```rust
use snafu::prelude::*;
use std::{fs, io, path::PathBuf};#[derive(Debug, Snafu)]
enum Error {
#[snafu(display("Unable to read configuration from {}", path.display()))]
ReadConfiguration { source: io::Error, path: PathBuf },#[snafu(display("Unable to write result to {}", path.display()))]
WriteResult { source: io::Error, path: PathBuf },
}type Result = std::result::Result;
fn process_data() -> Result<()> {
let path = "config.toml";
let configuration = fs::read_to_string(path).context(ReadConfigurationSnafu { path })?;
let path = unpack_config(&configuration);
fs::write(&path, b"My complex calculation").context(WriteResultSnafu { path })?;
Ok(())
}fn unpack_config(data: &str) -> &str {
"/some/path/that/does/not/exist"
}
```Please see [the documentation][Doc] and the [user's guide][Guide] for
a full description.[Crate]: https://crates.io/crates/snafu
[Crate Logo]: https://img.shields.io/crates/v/snafu.svg[Doc]: https://docs.rs/snafu
[Doc Logo]: https://docs.rs/snafu/badge.svg
[Guide]: https://docs.rs/snafu/*/snafu/guide/index.html[CI]: https://cirrus-ci.com/github/shepmaster/snafu
[CI Logo]: https://api.cirrus-ci.com/github/shepmaster/snafu.svg