issue_states/
error.rs

1// Issue states
2//
3// Copyright (c) 2018 Julian Ganz
4//
5// MIT License
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24//
25
26//! Obligatory error module
27//!
28//! This module provides an `Error` and a `Result` type for this library.
29
30use std::fmt;
31use std::error::Error as EError;
32use std::result::Result as RResult;
33
34
35
36
37/// Kinds of errors
38///
39pub enum ErrorKind {
40    /// A cyclic dependency was dected among a set of states
41    ///
42    /// Cyclic dependencies among issue states are forbidden.
43    ///
44    CyclicDependency,
45    /// An issue's dependency could not be resolved
46    ///
47    DependencyError,
48    ConditionParseError,
49}
50
51
52
53
54/// Error type for use within the library
55///
56pub struct Error {
57    kind: ErrorKind
58}
59
60
61impl From<ErrorKind> for Error {
62    fn from(kind: ErrorKind) -> Self {
63        Self {kind: kind}
64    }
65}
66
67
68impl fmt::Display for Error {
69    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
70        match self.kind {
71            ErrorKind::CyclicDependency => f.write_str("dependency cycle detected"),
72            ErrorKind::DependencyError => f.write_str("dependency resolution error"),
73            ErrorKind::ConditionParseError =>  f.write_str("could not parse condition"),
74        }
75    }
76}
77
78
79impl fmt::Debug for Error {
80    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
81        fmt::Display::fmt(self, f)
82    }
83}
84
85
86impl EError for Error {
87    fn description(&self) -> &str {
88        "Resolution failed"
89    }
90}
91
92
93
94
95/// Convenience Result type for use within the library
96///
97pub type Result<T> = RResult<T, Error>;
98