1#[cfg(feature = "chrono")]
17use chrono;
18use std::str::Utf8Error;
19
20#[derive(Debug, thiserror::Error)]
21pub enum Error {
22 #[error("bad parameter")]
23 BadParam,
24
25 #[error("I/O operation failed")]
27 Io(#[from] std::io::Error),
28
29 #[error("couldn't parse data as UTF-8")]
31 ParseUtf8(Utf8Error),
32
33 #[cfg(feature = "chrono")]
34 #[error("couldn't parse data")]
36 ParseChrono(#[from] chrono::ParseError),
37
38 #[error("couldn't get cargo metadata")]
40 CargoMetadataError(#[from] cargo_metadata::Error),
41
42 #[error(r#"couldn't open the Cargo.lock file: "{lock_file}""#)]
43 LockFileOpen {
44 lock_file: String,
45 open_error: std::io::Error,
46 },
47
48 #[error(r#"couldn't parse the Cargo.toml file: "{lock_file}""#)]
50 ParseCargoLockToml { lock_file: String },
51}
52
53impl Error {
54 pub fn from_file_open(lock_file: &str, open_error: std::io::Error) -> Self {
55 Self::LockFileOpen {
56 lock_file: lock_file.to_owned(),
57 open_error,
58 }
59 }
60
61 pub fn from_cargo_toml(lock_file: &str) -> Self {
62 Self::ParseCargoLockToml {
63 lock_file: lock_file.to_owned(),
64 }
65 }
66}