Capitalize example error messages

This commit is contained in:
David Tolnay 2019-11-15 21:14:50 -08:00
parent 74954bdbd7
commit 437c691d16
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 20 additions and 20 deletions

View File

@ -47,16 +47,16 @@ anyhow = "1.0"
fn main() -> Result<()> {
...
it.detach().context("failed to detach the important thing")?;
it.detach().context("Failed to detach the important thing")?;
let content = std::fs::read(path)
.with_context(|| format!("failed to read instrs from {}", path))?;
.with_context(|| format!("Failed to read instrs from {}", path))?;
...
}
```
```console
Error: failed to read instrs from ./path/to/instrs.jsox
Error: Failed to read instrs from ./path/to/instrs.jsox
Caused by:
No such file or directory (os error 2)
@ -88,12 +88,12 @@ anyhow = "1.0"
#[derive(Error, Debug)]
pub enum FormatError {
#[error("invalid header (expected {expected:?}, got {found:?})")]
#[error("Invalid header (expected {expected:?}, got {found:?})")]
InvalidHeader {
expected: String,
found: String,
},
#[error("missing attribute: {0}")]
#[error("Missing attribute: {0}")]
MissingAttribute(String),
}
```
@ -102,7 +102,7 @@ anyhow = "1.0"
supports string interpolation and produces an `anyhow::Error`.
```rust
return Err(anyhow!("missing attribute: {}", missing));
return Err(anyhow!("Missing attribute: {}", missing));
```
<br>

View File

@ -64,10 +64,10 @@
//! # let it = It;
//! # let path = "./path/to/instrs.jsox";
//! #
//! it.detach().context("failed to detach the important thing")?;
//! it.detach().context("Failed to detach the important thing")?;
//!
//! let content = std::fs::read(path)
//! .with_context(|| format!("failed to read instrs from {}", path))?;
//! .with_context(|| format!("Failed to read instrs from {}", path))?;
//! #
//! # const _: &str = stringify! {
//! ...
@ -78,7 +78,7 @@
//! ```
//!
//! ```console
//! Error: failed to read instrs from ./path/to/instrs.jsox
//! Error: Failed to read instrs from ./path/to/instrs.jsox
//!
//! Caused by:
//! No such file or directory (os error 2)
@ -136,12 +136,12 @@
//!
//! #[derive(Error, Debug)]
//! pub enum FormatError {
//! #[error("invalid header (expected {expected:?}, got {found:?})")]
//! #[error("Invalid header (expected {expected:?}, got {found:?})")]
//! InvalidHeader {
//! expected: String,
//! found: String,
//! },
//! #[error("missing attribute: {0}")]
//! #[error("Missing attribute: {0}")]
//! MissingAttribute(String),
//! }
//! ```
@ -154,7 +154,7 @@
//! #
//! # fn demo() -> Result<()> {
//! # let missing = "...";
//! return Err(anyhow!("missing attribute: {}", missing));
//! return Err(anyhow!("Missing attribute: {}", missing));
//! # Ok(())
//! # }
//! ```
@ -206,14 +206,14 @@ pub use anyhow as format_err;
/// which you constructed your anyhow::Error.
///
/// ```console
/// failed to read instrs from ./path/to/instrs.jsox
/// Failed to read instrs from ./path/to/instrs.jsox
/// ```
///
/// To print causes as well using anyhow's default formatting of causes, use the
/// alternate selector "{:#}".
///
/// ```console
/// failed to read instrs from ./path/to/instrs.jsox: No such file or directory (os error 2)
/// Failed to read instrs from ./path/to/instrs.jsox: No such file or directory (os error 2)
/// ```
///
/// The Debug format "{:?}" includes your backtrace if one was captured. Note
@ -221,7 +221,7 @@ pub use anyhow as format_err;
/// from `fn main` instead of printing it explicitly yourself.
///
/// ```console
/// Error: failed to read instrs from ./path/to/instrs.jsox
/// Error: Failed to read instrs from ./path/to/instrs.jsox
///
/// Caused by:
/// No such file or directory (os error 2)
@ -246,7 +246,7 @@ pub use anyhow as format_err;
///
/// ```console
/// Error {
/// context: "failed to read instrs from ./path/to/instrs.jsox",
/// context: "Failed to read instrs from ./path/to/instrs.jsox",
/// source: Os {
/// code: 2,
/// kind: NotFound,
@ -384,11 +384,11 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
/// }
///
/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {
/// it.detach().context("failed to detach the important thing")?;
/// it.detach().context("Failed to detach the important thing")?;
///
/// let path = &it.path;
/// let content = fs::read(path)
/// .with_context(|| format!("failed to read instrs from {}", path.display()))?;
/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?;
///
/// Ok(content)
/// }
@ -398,7 +398,7 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
/// level underlying causes would be enumerated below.
///
/// ```console
/// Error: failed to read instrs from ./path/to/instrs.jsox
/// Error: Failed to read instrs from ./path/to/instrs.jsox
///
/// Caused by:
/// No such file or directory (os error 2)
@ -439,7 +439,7 @@ pub type Result<T, E = Error> = std::result::Result<T, E>;
/// use anyhow::{Context, Result};
///
/// fn do_it() -> Result<()> {
/// helper().context("failed to complete the work")?;
/// helper().context("Failed to complete the work")?;
/// # const IGNORE: &str = stringify! {
/// ...
/// # };