aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-08 01:21:07 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-08 01:21:07 +0000
commit7da5cdaff174d28457664d484978e22e450e0d83 (patch)
treee169e0efa6e3a116cfdeac9f25140ba6df0d4c01
parent009201b7ce800bf1c6ae80015fa100deb83406c9 (diff)
parent208592ca1d66cebd1ee12ea2fa142149799596c4 (diff)
downloadmiette-simpleperf-release.tar.gz
Snap for 11421525 from 208592ca1d66cebd1ee12ea2fa142149799596c4 to simpleperf-releasesimpleperf-release
Change-Id: I1ea0d1092efbd3c828d0a4b2e5b812b9975f80b4
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp2
-rw-r--r--CHANGELOG.md7
-rw-r--r--Cargo.toml4
-rw-r--r--Cargo.toml.orig4
-rw-r--r--METADATA25
-rw-r--r--README.md79
-rw-r--r--README.tpl4
-rw-r--r--src/eyreish/macros.rs5
-rw-r--r--src/lib.rs14
-rw-r--r--src/protocol.rs24
11 files changed, 110 insertions, 60 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index dea8a89..189e9d2 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "91e5f5b7e347b921921bac7135c56c600abb1fab"
+ "sha1": "f4d056e1ffeb9a0bf36e2a6501365bd7e00db22d"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index cdb4796..fb5ed12 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,7 +5,7 @@ rust_library_host {
name: "libmiette",
crate_name: "miette",
cargo_env_compat: true,
- cargo_pkg_version: "5.9.0",
+ cargo_pkg_version: "5.10.0",
srcs: ["src/lib.rs"],
edition: "2018",
features: ["default"],
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0b842de..955c27d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
# `miette` Release Changelog
+<a name="5.10.0"></a>
+## 5.10.0 (2023-07-16)
+
+### Features
+
+* **protocol:** add StdError impl for Box<dyn Diagnostic + Send + Sync> (#273) ([2e3e5c9d](https://github.com/zkat/miette/commit/2e3e5c9d15e234495369e9b47d032644dd5664ad))
+
<a name="5.9.0"></a>
## 5.9.0 (2023-05-18)
diff --git a/Cargo.toml b/Cargo.toml
index 712a834..4c57331 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.56.0"
name = "miette"
-version = "5.9.0"
+version = "5.10.0"
authors = ["Kat Marchán <kzm@zkat.tech>"]
exclude = [
"images/",
@@ -43,7 +43,7 @@ version = "0.4.0"
optional = true
[dependencies.miette-derive]
-version = "=5.9.0"
+version = "=5.10.0"
[dependencies.once_cell]
version = "1.8.0"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 160556f..dd6e584 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "miette"
-version = "5.9.0"
+version = "5.10.0"
authors = ["Kat Marchán <kzm@zkat.tech>"]
description = "Fancy diagnostic reporting library and protocol for us mere mortals who aren't compiler hackers."
categories = ["rust-patterns"]
@@ -14,7 +14,7 @@ exclude = ["images/", "tests/", "miette-derive/"]
[dependencies]
thiserror = "1.0.40"
-miette-derive = { path = "miette-derive", version = "=5.9.0" }
+miette-derive = { path = "miette-derive", version = "=5.10.0" }
once_cell = "1.8.0"
unicode-width = "0.1.9"
diff --git a/METADATA b/METADATA
index 873e6bd..72c5386 100644
--- a/METADATA
+++ b/METADATA
@@ -1,19 +1,20 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/miette
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "miette"
description: "Fancy diagnostic reporting library and protocol for us mere mortals who aren\'t compiler hackers."
third_party {
- url {
- type: HOMEPAGE
- value: "https://crates.io/crates/miette"
- }
- url {
- type: ARCHIVE
- value: "https://static.crates.io/crates/miette/miette-5.9.0.crate"
- }
- version: "5.9.0"
license_type: NOTICE
last_upgrade_date {
- year: 2023
- month: 6
- day: 12
+ year: 2024
+ month: 2
+ day: 2
+ }
+ homepage: "https://crates.io/crates/miette"
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/miette/miette-5.10.0.crate"
+ version: "5.10.0"
}
}
diff --git a/README.md b/README.md
index ff25b3a..7aabe99 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
You run miette? You run her code like the software? Oh. Oh! Error code for
coder! Error code for One Thousand Lines!
-## About
+### About
`miette` is a diagnostic library for Rust. It includes a series of
traits/protocols that allow you to hook into its error reporting facilities,
@@ -32,7 +32,7 @@ output like in the screenshots above.** You should only do this in your
toplevel crate, as the fancy feature pulls in a number of dependencies that
libraries and such might not want.
-## Table of Contents <!-- omit in toc -->
+### Table of Contents <!-- omit in toc -->
- [About](#about)
- [Features](#features)
@@ -51,7 +51,7 @@ libraries and such might not want.
- [Acknowledgements](#acknowledgements)
- [License](#license)
-## Features
+### Features
- Generic [`Diagnostic`] protocol, compatible (and dependent on)
[`std::error::Error`].
@@ -76,7 +76,7 @@ the following features:
- Cause chain printing
- Turns diagnostic codes into links in [supported terminals](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda).
-## Installing
+### Installing
```sh
$ cargo add miette
@@ -88,7 +88,7 @@ If you want to use the fancy printer in all these screenshots:
$ cargo add miette --features fancy
```
-## Example
+### Example
```rust
/*
@@ -170,9 +170,9 @@ diagnostic help: Change int or string to be the right types and try again.
diagnostic code: nu::parser::unsupported_operation
For more details, see https://docs.rs/nu-parser/0.1.0/nu-parser/enum.ParseError.html#variant.UnsupportedOperation">
-## Using
+### Using
-### ... in libraries
+#### ... in libraries
`miette` is _fully compatible_ with library usage. Consumers who don't know
about, or don't want, `miette` features can safely use its error types as
@@ -187,7 +187,7 @@ the trait directly, just like with `std::error::Error`.
```rust
// lib/error.rs
-use miette::Diagnostic;
+use miette::{Diagnostic, SourceSpan};
use thiserror::Error;
#[derive(Error, Diagnostic, Debug)]
@@ -199,6 +199,18 @@ pub enum MyLibError {
#[error("Oops it blew up")]
#[diagnostic(code(my_lib::bad_code))]
BadThingHappened,
+
+ #[error(transparent)]
+ // Use `#[diagnostic(transparent)]` to wrap another [`Diagnostic`]. You won't see labels otherwise
+ #[diagnostic(transparent)]
+ AnotherError(#[from] AnotherError),
+}
+
+#[derive(Error, Diagnostic, Debug)]
+#[error("another error")]
+pub struct AnotherError {
+ #[label("here")]
+ pub at: SourceSpan
}
```
@@ -206,7 +218,7 @@ Then, return this error type from all your fallible public APIs. It's a best
practice to wrap any "external" error types in your error `enum` instead of
using something like [`Report`] in a library.
-### ... in application code
+#### ... in application code
Application code tends to work a little differently than libraries. You
don't always need or care to define dedicated error wrappers for errors
@@ -248,8 +260,7 @@ pub fn some_tool() -> Result<Version> {
}
```
-To construct your own simple adhoc error use the [`miette!`] macro:
-
+To construct your own simple adhoc error use the [miette!] macro:
```rust
// my_app/lib/my_internal_file.rs
use miette::{miette, IntoDiagnostic, Result, WrapErr};
@@ -262,8 +273,9 @@ pub fn some_tool() -> Result<Version> {
.map_err(|_| miette!("Invalid version {}", version))?)
}
```
+There are also similar [bail!] and [ensure!] macros.
-### ... in `main()`
+#### ... in `main()`
`main()` is just like any other part of your application-internal code. Use
`Result` as your return value, and it will pretty-print your diagnostics
@@ -293,7 +305,7 @@ enabled:
miette = { version = "X.Y.Z", features = ["fancy"] }
```
-### ... diagnostic code URLs
+#### ... diagnostic code URLs
`miette` supports providing a URL for individual diagnostics. This URL will
be displayed as an actual link in supported terminals, like so:
@@ -346,7 +358,7 @@ use thiserror::Error;
struct MyErr;
```
-### ... snippets
+#### ... snippets
Along with its general error handling and reporting features, `miette` also
includes facilities for adding error spans/annotations/labels to your
@@ -394,7 +406,7 @@ pub struct MyErrorType {
}
```
-#### ... help text
+##### ... help text
`miette` provides two facilities for supplying help text for your errors:
The first is the `#[help()]` format attribute that applies to structs or
@@ -430,7 +442,7 @@ let err = Foo {
};
```
-### ... multiple related errors
+#### ... multiple related errors
`miette` supports collecting multiple errors into a single diagnostic, and
printing them all together nicely.
@@ -450,7 +462,7 @@ struct MyError {
}
```
-### ... delayed source code
+#### ... delayed source code
Sometimes it makes sense to add source code to the error message later.
One option is to use [`with_source_code()`](Report::with_source_code)
@@ -533,7 +545,7 @@ fn main() -> miette::Result<()> {
}
```
-### ... Diagnostic-based error sources.
+#### ... Diagnostic-based error sources.
When one uses the `#[source]` attribute on a field, that usually comes
from `thiserror`, and implements a method for
@@ -566,7 +578,7 @@ struct MyError {
struct OtherError;
```
-### ... handler options
+#### ... handler options
[`MietteHandler`] is the default handler, and is very customizable. In
most cases, you can simply use [`MietteHandlerOpts`] to tweak its behavior
@@ -585,12 +597,13 @@ miette::set_hook(Box::new(|_| {
.build(),
)
}))
+
```
See the docs for [`MietteHandlerOpts`] for more details on what you can
customize!
-### ... dynamic diagnostics
+#### ... dynamic diagnostics
If you...
- ...don't know all the possible errors upfront
@@ -599,6 +612,7 @@ then you may want to use [`miette!`], [`diagnostic!`] macros or
[`MietteDiagnostic`] directly to create diagnostic on the fly.
```rust
+
let source = "2 + 2 * 2 = 8".to_string();
let report = miette!(
labels = vec[
@@ -610,26 +624,25 @@ let report = miette!(
println!("{:?}", report)
```
-## Acknowledgements
+### Acknowledgements
`miette` was not developed in a void. It owes enormous credit to various
other projects and their authors:
-- [`anyhow`](http://crates.io/crates/anyhow) and
- [`color-eyre`](https://crates.io/crates/color-eyre): these two
- enormously influential error handling libraries have pushed forward the
- experience of application-level error handling and error reporting.
- `miette`'s `Report` type is an attempt at a very very rough version of
- their `Report` types.
-- [`thiserror`](https://crates.io/crates/thiserror) for setting the
- standard for library-level error definitions, and for being the
- inspiration behind `miette`'s derive macro.
+- [`anyhow`](http://crates.io/crates/anyhow) and [`color-eyre`](https://crates.io/crates/color-eyre):
+ these two enormously influential error handling libraries have pushed
+ forward the experience of application-level error handling and error
+ reporting. `miette`'s `Report` type is an attempt at a very very rough
+ version of their `Report` types.
+- [`thiserror`](https://crates.io/crates/thiserror) for setting the standard
+ for library-level error definitions, and for being the inspiration behind
+ `miette`'s derive macro.
- `rustc` and [@estebank](https://github.com/estebank) for their
state-of-the-art work in compiler diagnostics.
- [`ariadne`](https://crates.io/crates/ariadne) for pushing forward how
_pretty_ these diagnostics can really look!
-## License
+### License
`miette` is released to the Rust community under the [Apache license
2.0](./LICENSE).
@@ -648,7 +661,7 @@ under the Apache License. Some code is taken from
[`MietteHandler`]: https://docs.rs/miette/latest/miette/struct.MietteHandler.html
[`MietteDiagnostic`]: https://docs.rs/miette/latest/miette/struct.MietteDiagnostic.html
[`Report`]: https://docs.rs/miette/latest/miette/struct.Report.html
-[`ReportHandler`]: https://docs.rs/miette/latest/miette/struct.ReportHandler.html
+[`ReportHandler`]: https://docs.rs/miette/latest/miette/trait.ReportHandler.html
[`Result`]: https://docs.rs/miette/latest/miette/type.Result.html
-[`SourceCode`]: https://docs.rs/miette/latest/miette/struct.SourceCode.html
+[`SourceCode`]: https://docs.rs/miette/latest/miette/trait.SourceCode.html
[`SourceSpan`]: https://docs.rs/miette/latest/miette/struct.SourceSpan.html
diff --git a/README.tpl b/README.tpl
index d598eb8..f1126f1 100644
--- a/README.tpl
+++ b/README.tpl
@@ -12,7 +12,7 @@
[`MietteHandler`]: https://docs.rs/miette/latest/miette/struct.MietteHandler.html
[`MietteDiagnostic`]: https://docs.rs/miette/latest/miette/struct.MietteDiagnostic.html
[`Report`]: https://docs.rs/miette/latest/miette/struct.Report.html
-[`ReportHandler`]: https://docs.rs/miette/latest/miette/struct.ReportHandler.html
+[`ReportHandler`]: https://docs.rs/miette/latest/miette/trait.ReportHandler.html
[`Result`]: https://docs.rs/miette/latest/miette/type.Result.html
-[`SourceCode`]: https://docs.rs/miette/latest/miette/struct.SourceCode.html
+[`SourceCode`]: https://docs.rs/miette/latest/miette/trait.SourceCode.html
[`SourceSpan`]: https://docs.rs/miette/latest/miette/struct.SourceSpan.html
diff --git a/src/eyreish/macros.rs b/src/eyreish/macros.rs
index 938ac32..e13309f 100644
--- a/src/eyreish/macros.rs
+++ b/src/eyreish/macros.rs
@@ -222,6 +222,9 @@ macro_rules! ensure {
/// ## `anyhow`/`eyre` Users
///
/// You can just replace `use`s of the `anyhow!`/`eyre!` macros with `miette!`.
+///
+/// [`diagnostic!`]: crate::diagnostic!
+/// [`Report`]: crate::Report
#[macro_export]
macro_rules! miette {
($($key:ident = $value:expr,)* $fmt:literal $($arg:tt)*) => {
@@ -282,6 +285,8 @@ macro_rules! miette {
)]
/// assert_eq!(diag.message, "1 + 2 = 3");
/// ```
+///
+/// [`MietteDiagnostic`]: crate::MietteDiagnostic
#[macro_export]
macro_rules! diagnostic {
($fmt:literal $($arg:tt)*) => {{
diff --git a/src/lib.rs b/src/lib.rs
index cc113ce..20589ef 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -186,7 +186,7 @@
//!
//! ```rust
//! // lib/error.rs
-//! use miette::Diagnostic;
+//! use miette::{Diagnostic, SourceSpan};
//! use thiserror::Error;
//!
//! #[derive(Error, Diagnostic, Debug)]
@@ -198,6 +198,18 @@
//! #[error("Oops it blew up")]
//! #[diagnostic(code(my_lib::bad_code))]
//! BadThingHappened,
+//!
+//! #[error(transparent)]
+//! // Use `#[diagnostic(transparent)]` to wrap another [`Diagnostic`]. You won't see labels otherwise
+//! #[diagnostic(transparent)]
+//! AnotherError(#[from] AnotherError),
+//! }
+//!
+//! #[derive(Error, Diagnostic, Debug)]
+//! #[error("another error")]
+//! pub struct AnotherError {
+//! #[label("here")]
+//! pub at: SourceSpan
//! }
//! ```
//!
diff --git a/src/protocol.rs b/src/protocol.rs
index 7531db1..f516984 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -69,14 +69,26 @@ pub trait Diagnostic: std::error::Error {
}
}
-impl std::error::Error for Box<dyn Diagnostic> {
- fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- (**self).source()
+macro_rules! box_impls {
+ ($($box_type:ty),*) => {
+ $(
+ impl std::error::Error for $box_type {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ (**self).source()
+ }
+
+ fn cause(&self) -> Option<&dyn std::error::Error> {
+ self.source()
+ }
+ }
+ )*
}
+}
- fn cause(&self) -> Option<&dyn std::error::Error> {
- self.source()
- }
+box_impls! {
+ Box<dyn Diagnostic>,
+ Box<dyn Diagnostic + Send>,
+ Box<dyn Diagnostic + Send + Sync>
}
impl<T: Diagnostic + Send + Sync + 'static> From<T>