| 1 |
use std::{io, str::Utf8Error, string::FromUtf8Error}; |
| 2 |
|
| 3 |
/// Custom result type for `cargo_metadata::Error` |
| 4 |
pub type Result<T> = ::std::result::Result<T, Error>; |
| 5 |
|
| 6 |
/// Error returned when executing/parsing `cargo metadata` fails. |
| 7 |
/// |
| 8 |
/// # Note about Backtraces |
| 9 |
/// |
| 10 |
/// This error type does not contain backtraces, but each error variant |
| 11 |
/// comes from _one_ specific place, so it's not really needed for the |
| 12 |
/// inside of this crate. If you need a backtrace down to, but not inside |
| 13 |
/// of, a failed call of `cargo_metadata` you can do one of multiple thinks: |
| 14 |
/// |
| 15 |
/// 1. Convert it to a `failure::Error` (possible using the `?` operator), |
| 16 |
/// which is similar to a `Box<::std::error::Error + 'static + Send + Sync>`. |
| 17 |
/// 2. Have appropriate variants in your own error type. E.g. you could wrap |
| 18 |
/// a `failure::Context<Error>` or add a `failure::Backtrace` field (which |
| 19 |
/// is empty if `RUST_BACKTRACE` is not set, so it's simple to use). |
| 20 |
/// 3. You still can place a failure based error into a `error_chain` if you |
| 21 |
/// really want to. (Either through foreign_links or by making it a field |
| 22 |
/// value of a `ErrorKind` variant). |
| 23 |
/// |
| 24 |
#[derive(Debug, thiserror::Error)] |
| 25 |
pub enum Error { |
| 26 |
/// Error during execution of `cargo metadata` |
| 27 |
#[error("`cargo metadata` exited with an error: {stderr}")] |
| 28 |
CargoMetadata { |
| 29 |
/// stderr returned by the `cargo metadata` command |
| 30 |
stderr: String, |
| 31 |
}, |
| 32 |
|
| 33 |
/// IO Error during execution of `cargo metadata` |
| 34 |
#[error("failed to start `cargo metadata`: {0}")] |
| 35 |
Io(#[from] io::Error), |
| 36 |
|
| 37 |
/// Output of `cargo metadata` was not valid utf8 |
| 38 |
#[error("cannot convert the stdout of `cargo metadata`: {0}")] |
| 39 |
Utf8(#[from] Utf8Error), |
| 40 |
|
| 41 |
/// Error output of `cargo metadata` was not valid utf8 |
| 42 |
#[error("cannot convert the stderr of `cargo metadata`: {0}")] |
| 43 |
ErrUtf8(#[from] FromUtf8Error), |
| 44 |
|
| 45 |
/// Deserialization error (structure of json did not match expected structure) |
| 46 |
#[error("failed to interpret `cargo metadata`'s json: {0}")] |
| 47 |
Json(#[from] ::serde_json::Error), |
| 48 |
|
| 49 |
/// The output did not contain any json |
| 50 |
#[error("could not find any json in the output of `cargo metadata`")] |
| 51 |
NoJson, |
| 52 |
} |