#error #helper #library

torrust-tracker-located-error

A library to provide error decorator with the location and the source of the original error

5 releases

3.0.0-alpha.11 Sep 18, 2023
3.0.0-alpha.10 Sep 16, 2023
3.0.0-alpha.3 Jul 10, 2023
3.0.0-alpha.2 Apr 13, 2023
3.0.0-alpha.1 Mar 17, 2023

#123 in #library

45 downloads per month
Used in 3 crates (2 directly)

Custom license

15KB
87 lines

Torrust Tracker Located Error

A library to provide an error decorator with the location and the source of the original error.

Documentation

Crate documentation.

License

The project is licensed under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE.


lib.rs:

This crate provides a wrapper around an error that includes the location of the error.

use std::error::Error;
use std::panic::Location;
use std::sync::Arc;
use torrust_tracker_located_error::{Located, LocatedError};

#[derive(thiserror::Error, Debug)]
enum TestError {
    #[error("Test")]
    Test,
}

#[track_caller]
fn get_caller_location() -> Location<'static> {
    *Location::caller()
}

let e = TestError::Test;

let b: LocatedError<TestError> = Located(e).into();
let l = get_caller_location();

assert!(b.to_string().contains("Test, src/lib.rs"));

Credits

https://stackoverflow.com/questions/74336993/getting-line-numbers-with-when-using-boxdyn-stderrorerror

Dependencies

~87KB