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

Automatically convert to external errors w/ ensure! and bail! #95

Merged

Commits on Nov 25, 2023

  1. Automatically convert to external errors

    A pattern documented by thiserror is
    
    ```
    pub enum MyError {
      ...
    
      #[error(transparent)]
      Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
    }
    ```
    
    It'd be nice for this to work with ensure! but right now, that macro returns
    an eyre error.
    
    With this PR, the macro additionally runs an .into(). In the case that
    the return type is an eyre error, obviously .into() will do nothing and
    be compiled away. In the case that there is a from method, the wrapping
    will occur. This enables eyre to be used for ergonomic 'implementation
    detail error' in a thiserror using system which has contractual errors.
    
    Since this conversion adds more flexibility to the result of these
    macros, this could break code which relies on the narrowness to inform
    type inference. If this is the case, update your code to specify the
    result type you would like to use.
    j-baker authored and thenorili committed Nov 25, 2023
    Configuration menu
    Copy the full SHA
    697a11d View commit details
    Browse the repository at this point in the history
  2. Fix single-argument ensure test and allow dead code.

    By adding the possibility for polymorphism from an eyre error, the
    previous commit breaks a previous eyre test for single-argument
    ensure!().
    
    This change fixes that test and adds `allow(dead_code)` to the struct
    used for the test for automatically converting to external errors.
    thenorili committed Nov 25, 2023
    Configuration menu
    Copy the full SHA
    9b6a4f6 View commit details
    Browse the repository at this point in the history