5 releases

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

#5 in #nydus

Download history 9/week @ 2023-12-17 9/week @ 2023-12-24 11/week @ 2023-12-31 4/week @ 2024-01-07 1/week @ 2024-01-14 2/week @ 2024-01-21 7/week @ 2024-01-28 1/week @ 2024-02-04 25/week @ 2024-02-11 88/week @ 2024-02-18 81/week @ 2024-02-25 37/week @ 2024-03-03 61/week @ 2024-03-10 21/week @ 2024-03-17 5/week @ 2024-03-24 107/week @ 2024-03-31

199 downloads per month
Used in 5 crates (3 directly)

Apache-2.0 OR BSD-3-Clause

11KB
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

~3–5MB
~106K SLoC