release_manager/
error.rs

1// This file is part of Release Manager
2
3// Release Manager is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// Release Manager is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with Release Manager  If not, see <http://www.gnu.org/licenses/>.
15
16use 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    /// Error performing io
26    IO(IOError),
27    /// Error reading from TOML strings
28    TomlRead(TomlReadError),
29    /// Error writing to TOML strings
30    TomlWrite(TomlWriteError),
31    /// Error while zipping file
32    Zip(ZipError),
33    /// Zip placement path doesn't exist
34    ZipPath,
35    /// Path could not be converted to string
36    PathString,
37    /// Target specified is not supported
38    InvalidTarget,
39    /// Target crate has no [package] section
40    PackageMissing,
41    /// Target crate has no name
42    NameMissing,
43    /// Target crate has no version
44    VersionMissing,
45    /// Expected a string (when parsing toml)
46    NotString,
47    /// Expected a table (when parsing toml)
48    NotTable,
49    /// Cannot publish already published crate
50    RePublish,
51    /// Some builds failed
52    FailedBuilds,
53    /// Failed to parse Config
54    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}