1use failure::Fail;
2
3#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Fail)]
5pub enum Error {
6 #[fail(display = "Failed to read/write the template! Error: {}", _0)]
7 File(String),
8 #[fail(display = "Failed to query the crate! Error: {}", _0)]
9 Crate(String),
10 #[fail(display = "Failed to query the gem! Error: {}", _0)]
11 Gem(String),
12 #[fail(display = "Failed to query the perldist! Error: {}", _0)]
13 PerlDist(String),
14 #[fail(display = "Failed to convert UTF-8 to a string! Error: {}", _0)]
15 UTF8(String),
16 #[fail(display = "Failed to write the template! Error: {}", _0)]
17 TmplWriter(String),
18 #[fail(display = "Failed to update the template! Error: {}", _0)]
19 TmplUpdater(String),
20 #[fail(display = "Won't write package for built-in template {}", _0)]
21 BuiltIn(String),
22 #[fail(
23 display = "Failed to determine git username/email from environment or git config! Error: {}",
24 _0
25 )]
26 Git(String),
27 #[fail(display = "Failed to determine XBPS_DISTDIR: {}", _0)]
28 Xdist(String),
29 #[fail(
30 display = "Found a package matching the specified package {}! Please explicitly choose one via the `-t` parameter!",
31 _0
32 )]
33 AmbPkg(String),
34 #[fail(
35 display = "Unable to determine what type of the target package {} is! Make sure you've spelled the package name correctly!",
36 _0
37 )]
38 NoSuchPkg(String),
39 #[fail(
40 display = "Failed to write checksum to the newly written template! Error: {}",
41 _0
42 )]
43 Sha(String),
44 #[fail(display = "Didn't provide enough info for action {}", _0)]
45 TooLittleInfo(String),
46 #[fail(
47 display = "Failed to write templates for all recursive deps of {}! Error: {}",
48 pkg_name, err
49 )]
50 RecDeps { pkg_name: String, err: String },
51 #[fail(display = "Can't run method {}! {}", method, err)]
52 WrongUsage { method: String, err: String },
53 #[fail(display = "{}", _0)]
54 Reqwest(String),
55}
56
57impl From<crates_io_api::Error> for Error {
58 fn from(e: crates_io_api::Error) -> Self {
59 Error::Crate(e.to_string())
60 }
61}
62
63impl From<rubygems_api::Error> for Error {
64 fn from(e: rubygems_api::Error) -> Self {
65 Error::Gem(e.to_string())
66 }
67}
68
69impl From<metacpan_api::Error> for Error {
70 fn from(e: metacpan_api::Error) -> Self {
71 Error::PerlDist(e.to_string())
72 }
73}
74
75impl From<std::str::Utf8Error> for Error {
76 fn from(e: std::str::Utf8Error) -> Self {
77 Error::UTF8(e.to_string())
78 }
79}
80
81impl From<std::io::Error> for Error {
82 fn from(e: std::io::Error) -> Self {
83 Error::File(e.to_string())
84 }
85}
86
87impl From<reqwest::Error> for Error {
88 fn from(e: reqwest::Error) -> Self {
89 Error::Reqwest(e.to_string())
90 }
91}
92
93impl From<reqwest::UrlError> for Error {
94 fn from(e: reqwest::UrlError) -> Self {
95 Error::Reqwest(e.to_string())
96 }
97}
98
99impl From<git2::Error> for Error {
100 fn from(e: git2::Error) -> Self {
101 Error::Git(e.to_string())
102 }
103}