diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:41 +0000 |
commit | 4f9fe856a25ab29345b90e7725509e9ee38a37be (patch) | |
tree | e4ffd8a9374cae7b21f7cbfb352927e0e074aff6 /vendor/cargo_metadata/src/errors.rs | |
parent | Adding upstream version 1.68.2+dfsg1. (diff) | |
download | rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.tar.xz rustc-5cd5bd4daf55da04d2c8e7c06c3067a027cfbfc2.zip |
Adding upstream version 1.69.0+dfsg1.upstream/1.69.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/cargo_metadata/src/errors.rs | 82 |
1 files changed, 12 insertions, 70 deletions
diff --git a/vendor/cargo_metadata/src/errors.rs b/vendor/cargo_metadata/src/errors.rs index 7172057e7..4d08200c8 100644 --- a/vendor/cargo_metadata/src/errors.rs +++ b/vendor/cargo_metadata/src/errors.rs @@ -1,7 +1,4 @@ -use std::fmt; -use std::io; -use std::str::Utf8Error; -use std::string::FromUtf8Error; +use std::{io, str::Utf8Error, string::FromUtf8Error}; /// Custom result type for `cargo_metadata::Error` pub type Result<T> = ::std::result::Result<T, Error>; @@ -24,87 +21,32 @@ pub type Result<T> = ::std::result::Result<T, Error>; /// really want to. (Either through foreign_links or by making it a field /// value of a `ErrorKind` variant). /// -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] pub enum Error { /// Error during execution of `cargo metadata` + #[error("`cargo metadata` exited with an error: {stderr}")] CargoMetadata { /// stderr returned by the `cargo metadata` command stderr: String, }, /// IO Error during execution of `cargo metadata` - Io(io::Error), + #[error("failed to start `cargo metadata`: {0}")] + Io(#[from] io::Error), /// Output of `cargo metadata` was not valid utf8 - Utf8(Utf8Error), + #[error("cannot convert the stdout of `cargo metadata`: {0}")] + Utf8(#[from] Utf8Error), /// Error output of `cargo metadata` was not valid utf8 - ErrUtf8(FromUtf8Error), + #[error("cannot convert the stderr of `cargo metadata`: {0}")] + ErrUtf8(#[from] FromUtf8Error), /// Deserialization error (structure of json did not match expected structure) - Json(::serde_json::Error), + #[error("failed to interpret `cargo metadata`'s json: {0}")] + Json(#[from] ::serde_json::Error), /// The output did not contain any json + #[error("could not find any json in the output of `cargo metadata`")] NoJson, } - -impl From<io::Error> for Error { - fn from(v: io::Error) -> Self { - Error::Io(v) - } -} - -impl From<Utf8Error> for Error { - fn from(v: Utf8Error) -> Self { - Error::Utf8(v) - } -} - -impl From<FromUtf8Error> for Error { - fn from(v: FromUtf8Error) -> Self { - Error::ErrUtf8(v) - } -} - -impl From<::serde_json::Error> for Error { - fn from(v: ::serde_json::Error) -> Self { - Error::Json(v) - } -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Error::CargoMetadata { stderr } => { - write!( - f, - "`cargo metadata` exited with an error: {}", - stderr.trim_end() - ) - } - Error::Io(err) => write!(f, "failed to start `cargo metadata`: {}", err), - Error::Utf8(err) => write!(f, "cannot convert the stdout of `cargo metadata`: {}", err), - Error::ErrUtf8(err) => { - write!(f, "cannot convert the stderr of `cargo metadata`: {}", err) - } - Error::Json(err) => write!(f, "failed to interpret `cargo metadata`'s json: {}", err), - Error::NoJson => write!( - f, - "could not find any json in the output of `cargo metadata`" - ), - } - } -} - -impl ::std::error::Error for Error { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Error::CargoMetadata { .. } => None, - Error::Io(err) => Some(err), - Error::Utf8(err) => Some(err), - Error::ErrUtf8(err) => Some(err), - Error::Json(err) => Some(err), - Error::NoJson => None, - } - } -} |