Skip to content

Releases: dtolnay/anyhow

1.0.19

02 Nov 20:27
1.0.19
360c93a
Compare
Choose a tag to compare
  • Export anyhow! also under the alias format_err! (#37)

1.0.18

28 Oct 15:08
1.0.18
afa1a47
Compare
Choose a tag to compare
  • Support downcasting errors with context to the context's type C or to the underlying error type E (#34)

    That is, in codebases that rely on downcasting, Anyhow's context now supports both of the following use cases:

    • Attaching context whose type is insignificant onto errors whose type is used in downcasts.

      In other error libraries whose context is not designed this way, it can be risky to introduce context to existing code because new context might break existing working downcasts. In Anyhow, any downcast that worked before adding context will continue to work after you add a context, so you should freely add human-readable context to errors wherever it would be helpful.

      use anyhow::{Context, Result};
      
      fn do_it() -> Result<()> {
          helper().context("failed to complete the work")?;
          ...
      }
      
      fn main() {
          let err = do_it().unwrap_err();
          if let Some(e) = err.downcast_ref::<SuspiciousError>() {
              // If helper() returned SuspiciousError, this downcast will
              // correctly succeed even with the context in between.
          }
      }
    • Attaching context whose type is used in downcasts onto errors whose type is insignificant.

      Some codebases prefer to use machine-readable context to categorize lower level errors in a way that will be actionable to higher levels of the application.

      use anyhow::{Context, Result};
      
      fn do_it() -> Result<()> {
          helper().context(HelperFailed)?;
          ...
      }
      
      fn main() {
          let err = do_it().unwrap_err();
          if let Some(e) = err.downcast_ref::<HelperFailed>() {
              // If helper failed, this downcast will succeed because
              // HelperFailed is the context that has been attached to
              // that error.
          }
      }

1.0.17

21 Oct 18:26
1.0.17
810f73e
Compare
Choose a tag to compare
  • Work around poor paths in compiler diagnostic when missing Context import (#30)

1.0.16

19 Oct 21:51
1.0.16
2a5257a
Compare
Choose a tag to compare
  • Add impl From<anyhow::Error> for Box<dyn std::error::Error + 'static> (#25)

1.0.15

19 Oct 13:14
1.0.15
3570a5e
Compare
Choose a tag to compare
  • Documentation improvements

1.0.14

18 Oct 15:21
1.0.14
20fbcf3
Compare
Choose a tag to compare
  • Replace compiler version detection with probing the Backtrace api to be more resilient to nightly development of backtrace feature (#24)

1.0.13

13 Oct 16:11
1.0.13
d7c37d6
Compare
Choose a tag to compare
  • Support building with dev toolchains older than 1.40.0-nightly (#20)

1.0.12

12 Oct 01:33
1.0.12
f432c46
Compare
Choose a tag to compare
  • Improve return type inference when calling .context(...) on a Result (#18)

1.0.11

10 Oct 03:11
1.0.11
Compare
Choose a tag to compare
  • Fix UB when accessing errors with large alignment (#16, thanks @johnschug)

1.0.10

09 Oct 18:15
1.0.10
db8fa67
Compare
Choose a tag to compare
  • Documentation improvements: show example of thiserror's derive(Error)