Skip to content
Myr

Capitalize example error messages

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 74954bd · Browse files · 2 files+20 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−20 removed

  • other:+20 added−20 removed

2 files+20 added−20 removed

modified:src/lib.rs+14 added-14 removed
62 unmodified lines
63//! #64//! # let it = It;65//! # let path = "./path/to/instrs.jsox";66//! #67//! it.detach().context("failed to detach the important thing")?;67//! it.detach().context("Failed to detach the important thing")?;68//!69//! let content = std::fs::read(path)70//! .with_context(|| format!("failed to read instrs from {}", path))?;70//! .with_context(|| format!("Failed to read instrs from {}", path))?;71//! #72//! # const _: &str = stringify! {73//! ...74//! # };
2 unmodified lines
77//! }78//! ```79//!80//! ```console81//! Error: failed to read instrs from ./path/to/instrs.jsox81//! Error: Failed to read instrs from ./path/to/instrs.jsox82//!83//! Caused by:84//! No such file or directory (os error 2)85//! ```
49 unmodified lines
135//! use thiserror::Error;136//!137//! #[derive(Error, Debug)]138//! pub enum FormatError {139//! #[error("invalid header (expected {expected:?}, got {found:?})")]139//! #[error("Invalid header (expected {expected:?}, got {found:?})")]140//! InvalidHeader {141//! expected: String,142//! found: String,143//! },144//! #[error("missing attribute: {0}")]144//! #[error("Missing attribute: {0}")]145//! MissingAttribute(String),146//! }147//! ```148//!
4 unmodified lines
153//! # use anyhow::{anyhow, Result};154//! #155//! # fn demo() -> Result<()> {156//! # let missing = "...";157//! return Err(anyhow!("missing attribute: {}", missing));157//! return Err(anyhow!("Missing attribute: {}", missing));158//! # Ok(())159//! # }160//! ```161
43 unmodified lines
205/// This is exactly as if you had called the Display impl of the error from206/// which you constructed your anyhow::Error.207///208/// ```console209/// failed to read instrs from ./path/to/instrs.jsox209/// Failed to read instrs from ./path/to/instrs.jsox210/// ```211///212/// To print causes as well using anyhow's default formatting of causes, use the213/// alternate selector "{:#}".214///215/// ```console216/// failed to read instrs from ./path/to/instrs.jsox: No such file or directory (os error 2)216/// Failed to read instrs from ./path/to/instrs.jsox: No such file or directory (os error 2)217/// ```218///219/// The Debug format "{:?}" includes your backtrace if one was captured. Note220/// that this is the representation you get by default if you return an error221/// from `fn main` instead of printing it explicitly yourself.222///223/// ```console224/// Error: failed to read instrs from ./path/to/instrs.jsox224/// Error: Failed to read instrs from ./path/to/instrs.jsox225///226/// Caused by:227/// No such file or directory (os error 2)228///
16 unmodified lines
245/// To see a conventional struct-style Debug representation, use "{:#?}".246///247/// ```console248/// Error {249/// context: "failed to read instrs from ./path/to/instrs.jsox",249/// context: "Failed to read instrs from ./path/to/instrs.jsox",250/// source: Os {251/// code: 2,252/// kind: NotFound,253/// message: "No such file or directory",
129 unmodified lines
383/// # }384/// }385///386/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {387/// it.detach().context("failed to detach the important thing")?;387/// it.detach().context("Failed to detach the important thing")?;388///389/// let path = &it.path;390/// let content = fs::read(path)391/// .with_context(|| format!("failed to read instrs from {}", path.display()))?;391/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?;392///393/// Ok(content)394/// }395/// ```
1 unmodified line
397/// When printed, the outermost context would be printed first and the lower398/// level underlying causes would be enumerated below.399///400/// ```console401/// Error: failed to read instrs from ./path/to/instrs.jsox401/// Error: Failed to read instrs from ./path/to/instrs.jsox402///403/// Caused by:404/// No such file or directory (os error 2)405/// ```
32 unmodified lines
438/// #439/// use anyhow::{Context, Result};440///441/// fn do_it() -> Result<()> {442/// helper().context("failed to complete the work")?;442/// helper().context("Failed to complete the work")?;443/// # const IGNORE: &str = stringify! {444/// ...445/// # };446/// # unreachable!()
85 unmodified lines
modified:README.md+6 added-6 removed