5 releases

new 0.2.3 Jan 30, 2023
0.2.2 Nov 4, 2022
0.2.1 May 31, 2022
0.2.0 Feb 28, 2022
0.1.0 Aug 15, 2021

#95 in Filesystem

Download history 23/week @ 2022-10-10 14/week @ 2022-10-17 30/week @ 2022-10-24 62/week @ 2022-10-31 634/week @ 2022-11-07 618/week @ 2022-11-14 1184/week @ 2022-11-21 1002/week @ 2022-11-28 887/week @ 2022-12-05 889/week @ 2022-12-12 340/week @ 2022-12-19 213/week @ 2022-12-26 503/week @ 2023-01-02 567/week @ 2023-01-09 448/week @ 2023-01-16 536/week @ 2023-01-23

2,059 downloads per month
Used in 8 crates (7 directly)

Apache-2.0 OR BSD-3-Clause

10KB
173 lines

nydus-error

The nydus-error crate is a collection of helper utilities to handle error codes for Nydus Image Service project, which provides:

  • macro define_error_macro!() to optionally augment Posix errno with backtrace information.
  • macro einval!(), enoent!() etc for commonly used error codes.
  • struct ErrorHolder to provide a circular buffer to hold the latest error messages.

Support

Platforms:

  • x86_64
  • aarch64

Operating Systems:

  • Linux

Usage

Add nydus-error as a dependency in Cargo.toml

[dependencies]
nydus-error = "*"

Then add extern crate nydus-error; to your crate root if needed.

Examples

  • Return an error with backtracing information:
fn check_size(size: usize) -> std::io::Result<()> {
    if size > 0x1000 {
        return Err(einval!());
    }

    Ok(())
}
  • Put an error message into an ErrorHolder object.
fn record_error(size: usize) {
    let mut holder = ErrorHolder::new(10, 80);
    let error_msg = "123456789";
    let r = holder.push(error_msg);

    assert_eq!(r.is_ok(), true);
    let _msg = holder.export().unwrap();
}

License

This code is licensed under Apache-2.0 or BSD-3-Clause.

Dependencies

~5MB
~110K SLoC