]>
git.proxmox.com Git - rustc.git/blob - vendor/cargo_metadata/src/errors.rs
3 use std
::str::Utf8Error
;
4 use std
::string
::FromUtf8Error
;
6 /// Custom result type for `cargo_metadata::Error`
7 pub type Result
<T
> = ::std
::result
::Result
<T
, Error
>;
9 /// Error returned when executing/parsing `cargo metadata` fails.
11 /// # Note about Backtraces
13 /// This error type does not contain backtraces, but each error variant
14 /// comes from _one_ specific place, so it's not really needed for the
15 /// inside of this crate. If you need a backtrace down to, but not inside
16 /// of, a failed call of `cargo_metadata` you can do one of multiple thinks:
18 /// 1. Convert it to a `failure::Error` (possible using the `?` operator),
19 /// which is similar to a `Box<::std::error::Error + 'static + Send + Sync>`.
20 /// 2. Have appropriate variants in your own error type. E.g. you could wrap
21 /// a `failure::Context<Error>` or add a `failure::Backtrace` field (which
22 /// is empty if `RUST_BACKTRACE` is not set, so it's simple to use).
23 /// 3. You still can place a failure based error into a `error_chain` if you
24 /// really want to. (Either through foreign_links or by making it a field
25 /// value of a `ErrorKind` variant).
29 /// Error during execution of `cargo metadata`
31 /// stderr returned by the `cargo metadata` command
35 /// IO Error during execution of `cargo metadata`
38 /// Output of `cargo metadata` was not valid utf8
41 /// Error output of `cargo metadata` was not valid utf8
42 ErrUtf8(FromUtf8Error
),
44 /// Deserialization error (structure of json did not match expected structure)
45 Json(::serde_json
::Error
),
47 /// The output did not contain any json
51 impl From
<io
::Error
> for Error
{
52 fn from(v
: io
::Error
) -> Self {
57 impl From
<Utf8Error
> for Error
{
58 fn from(v
: Utf8Error
) -> Self {
63 impl From
<FromUtf8Error
> for Error
{
64 fn from(v
: FromUtf8Error
) -> Self {
69 impl From
<::serde_json
::Error
> for Error
{
70 fn from(v
: ::serde_json
::Error
) -> Self {
75 impl fmt
::Display
for Error
{
76 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
78 Error
::CargoMetadata { stderr }
=> {
79 write
!(f
, "Error during execution of `cargo metadata`: {}", stderr
)
81 Error
::Io(err
) => write
!(f
, "{}", err
),
82 Error
::Utf8(err
) => write
!(f
, "Cannot convert the stdout of `cargo metadata`: {}", err
),
83 Error
::ErrUtf8(err
) => {
84 write
!(f
, "Cannot convert the stderr of `cargo metadata`: {}", err
)
86 Error
::Json(err
) => write
!(f
, "Failed to interpret `cargo metadata`'s json: {}", err
),
87 Error
::NoJson
=> write
!(
89 "Could not find any json in the output of `cargo metadata`"
95 impl ::std
::error
::Error
for Error
{
96 fn source(&self) -> Option
<&(::std
::error
::Error
+ '
static)> {
98 Error
::CargoMetadata { .. }
=> None
,
99 Error
::Io(err
) => Some(err
),
100 Error
::Utf8(err
) => Some(err
),
101 Error
::ErrUtf8(err
) => Some(err
),
102 Error
::Json(err
) => Some(err
),
103 Error
::NoJson
=> None
,