Fix more references to old context design

This commit is contained in:
Jane Lusby 2020-03-05 18:40:22 -08:00
parent 8fc4e962a9
commit ecff17c22b
2 changed files with 19 additions and 23 deletions

View File

@ -184,15 +184,14 @@ where
ErrReport { inner }
}
/// Wrap the error value with additional context.
/// Create a new error from an error message to wrap the existing error.
///
/// For attaching context to a `Result` as it is propagated, the
/// [`WrapErr`][crate::WrapErr] extension trait may be more convenient than
/// this function.
/// For attaching a higher level error message to a `Result` as it is propagated, the
/// [`WrapErr`][crate::WrapErr] extension trait may be more convenient than this function.
///
/// The primary reason to use `error.context(...)` instead of
/// `result.context(...)` via the `WrapErr` trait would be if the context
/// needs to depend on some data held by the underlying error:
/// The primary reason to use `error.wrap_err(...)` instead of `result.wrap_err(...)` via the
/// `WrapErr` trait would be if the message needs to depend on some data held by the underlying
/// error:
///
/// ```
/// # use std::fmt::{self, Debug, Display};
@ -230,11 +229,11 @@ where
/// pub fn parse(path: impl AsRef<Path>) -> Result<T> {
/// let file = File::open(&path)?;
/// parse_impl(file).map_err(|error| {
/// let context = format!(
/// let message = format!(
/// "only the first {} lines of {} are valid",
/// error.line, path.as_ref().display(),
/// );
/// eyre::ErrReport::new(error).wrap_err(context)
/// eyre::ErrReport::new(error).wrap_err(message)
/// })
/// }
/// ```
@ -317,10 +316,9 @@ where
/// Returns true if `E` is the type held by this error object.
///
/// For errors with context, this method returns true if `E` matches the
/// type of the context `D` **or** the type of the error on which the
/// context has been attached. For details about the interaction between
/// context and downcasting, [see here].
/// For errors constructed from messages, this method returns true if `E` matches the type of
/// the message `D` **or** the type of the error on which the message has been attached. For
/// details about the interaction between message and downcasting, [see here].
///
/// [see here]: trait.WrapErr.html#effect-on-downcasting
pub fn is<E>(&self) -> bool

View File

@ -38,10 +38,9 @@
//! # fn main() {}
//! ```
//!
//! - Attach context to help the person troubleshooting the error understand
//! where things went wrong. A low-level error like "No such file or
//! directory" can be annoying to debug without more context about what higher
//! level step the application was in the middle of.
//! - Create new errors from messages to help the person troubleshooting the error understand where
//! things went wrong. A low-level error like "No such file or directory" can be annoying to
//! directly and often benefit from being wrapped with higher level error messages.
//!
//! ```
//! # struct It;
@ -250,10 +249,9 @@ pub use eyre as format_err;
///
/// # Display representations
///
/// When you print an error object using "{}" or to_string(), only the outermost
/// underlying error or context is printed, not any of the lower level causes.
/// This is exactly as if you had called the Display impl of the error from
/// which you constructed your eyre::ErrReport.
/// When you print an error object using "{}" or to_string(), only the outermost underlying error
/// is printed, not any of the lower level causes. This is exactly as if you had called the Display
/// impl of the error from which you constructed your eyre::ErrReport.
///
/// ```console
/// Failed to read instrs from ./path/to/instrs.json
@ -612,7 +610,7 @@ pub type Result<T, E = ErrReport<DefaultContext>> = core::result::Result<T, E>;
/// 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.
/// // correctly succeed even with the message in between.
/// # return;
/// }
/// # panic!("expected downcast to succeed");
@ -652,7 +650,7 @@ pub type Result<T, E = ErrReport<DefaultContext>> = core::result::Result<T, E>;
/// 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
/// // HelperFailed is the message that has been attached to
/// // that error.
/// # return;
/// }