1#[cfg(not(feature = "metadata"))]
2use crate::cm::Error as CMErr;
3#[cfg(feature = "metadata")]
4use cargo_metadata::Error as CMErr;
5use std::fmt;
6
7#[derive(Debug)]
9pub enum Error {
10 NoResolveGraph,
12 Metadata(CMErr),
14 InvalidPkgSpec(&'static str),
16 NoRootKrates,
19}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Self::NoResolveGraph => f.write_str("no resolution graph was provided"),
25 Self::Metadata(err) => write!(f, "{err}"),
26 Self::InvalidPkgSpec(err) => write!(f, "package spec was invalid: {err}"),
27 Self::NoRootKrates => f.write_str("no root crates available"),
28 }
29 }
30}
31
32impl std::error::Error for Error {
33 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34 match self {
35 Self::Metadata(err) => Some(err),
36 _ => None,
37 }
38 }
39}
40
41impl From<CMErr> for Error {
42 fn from(e: CMErr) -> Self {
43 Error::Metadata(e)
44 }
45}