#error #helper #library

torrust-index-located-error

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

5 releases (1 stable)

3.0.0 Oct 2, 2024
3.0.0-rc.1 Sep 24, 2024
3.0.0-beta Sep 3, 2024
3.0.0-alpha.12 Aug 13, 2024
3.0.0-alpha.2 Oct 15, 2023

#907 in Network programming


Used in torrust-index

AGPL-3.0-only

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

~1.7–2.4MB
~43K SLoC