Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor error handling #14

Merged
merged 3 commits into from
Dec 12, 2015
Merged

refactor error handling #14

merged 3 commits into from
Dec 12, 2015

Conversation

colin-kiegel
Copy link
Member

New suggestion for #1

/// Generic error with backtrace.
///
/// Wrapper around some error type `T` implementing `std::error::Error`.
/// * Adds support for a backtrace.
/// * Automatically derefs to the inner error.
pub struct Traced<T>
    where T: Error
{
    error: T,
    trace: Trace,
}

/// Trace wraps `Vec<Location>`  with specialized `Display` and `Debug` impls.
///
/// For everything else it just derefs to `Vec<Location>`.
pub struct Trace(Vec<Location>);

@colin-kiegel
Copy link
Member Author

PS:

  • The GeneralizeTo has disappeared. In this model we can just use Into
  • Extension trait ErrorExtfor T: std::error::Error adds conversion to Traced<T: Error>
  • I renamed the macros a little: try_traced! and traced_err!
pub trait ErrorExt: Error {
    /// Returns generic twig error for this error code.
    /// You must provide the location, where the error occured.
    fn at(self, location: Location) -> Traced<Self>
        where Self: Sized
    {
        Traced::new(self, location)
    }
}

impl<T> ErrorExt for T where T: Error {}

Nercury added a commit that referenced this pull request Dec 12, 2015
@Nercury Nercury merged commit e97211b into rust-web:master Dec 12, 2015
@Nercury
Copy link
Member

Nercury commented Dec 12, 2015

OK, let's try this.

@colin-kiegel colin-kiegel deleted the pr_error_handling branch December 12, 2015 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants