1use toml::de::Error as TomlReadError;
17use toml::ser::Error as TomlWriteError;
18use zip::result::ZipError;
19use std::io::Error as IOError;
20use std::path::StripPrefixError;
21use std::fmt;
22
23#[derive(Debug)]
24pub enum Error {
25 IO(IOError),
27 TomlRead(TomlReadError),
29 TomlWrite(TomlWriteError),
31 Zip(ZipError),
33 ZipPath,
35 PathString,
37 InvalidTarget,
39 PackageMissing,
41 NameMissing,
43 VersionMissing,
45 NotString,
47 NotTable,
49 RePublish,
51 FailedBuilds,
53 Config,
55}
56
57impl fmt::Display for Error {
58 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
59 match *self {
60 Error::IO(ref err) => write!(f, "IO Error: {}", err),
61 Error::TomlRead(ref err) => write!(f, "Error reading TOML: {}", err),
62 Error::TomlWrite(ref err) => write!(f, "Error writing TOML: {}", err),
63 Error::Zip(ref err) => write!(f, "Error making .zip: {}", err),
64 Error::ZipPath => write!(f, "Path for zip file is invalid"),
65 Error::PathString => write!(f, "Path could not be converted to string"),
66 Error::InvalidTarget => write!(f, "Supplied target is not supported"),
67 Error::PackageMissing => write!(f, "Crate is missing [package] section"),
68 Error::NameMissing => write!(f, "Crate is missing the 'name' parameter"),
69 Error::VersionMissing => write!(f, "Crate is missing the 'version' parameter"),
70 Error::NotString => write!(f, "Expected a toml::Value::String, got something else"),
71 Error::NotTable => write!(f, "Expected a toml::Value::Table, got somethign else"),
72 Error::RePublish => write!(f, "Cannot re-publish an already published crate"),
73 Error::FailedBuilds => write!(f, "Some builds failed"),
74 Error::Config => write!(f, "Error building config"),
75 }
76 }
77}
78
79impl From<IOError> for Error {
80 fn from(err: IOError) -> Self {
81 Error::IO(err)
82 }
83}
84
85impl From<TomlReadError> for Error {
86 fn from(err: TomlReadError) -> Self {
87 Error::TomlRead(err)
88 }
89}
90
91impl From<TomlWriteError> for Error {
92 fn from(err: TomlWriteError) -> Self {
93 Error::TomlWrite(err)
94 }
95}
96
97impl From<ZipError> for Error {
98 fn from(err: ZipError) -> Self {
99 Error::Zip(err)
100 }
101}
102
103impl From<StripPrefixError> for Error {
104 fn from(_: StripPrefixError) -> Self {
105 Error::ZipPath
106 }
107}