1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::error::Error as StdError;
use std::fmt::Result as FmtResult;
use std::fmt::{Display, Formatter};
use std::result::Result as StdResult;
use config::ConfigError;
use core;
use renderer;
pub type Result<T> = StdResult<T, Error>;
#[derive(Debug)]
pub enum Error {
Application,
Config(ConfigError),
Core(core::Error),
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Application => "Application error!",
Error::Config(_) => "Configuration error!",
Error::Core(_) => "Core error!",
}
}
fn cause(&self) -> Option<&StdError> {
match *self {
Error::Config(ref e) => Some(e),
_ => None,
}
}
}
impl Display for Error {
fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
match *self {
Error::Application => write!(fmt, "Application initialization failed!"),
Error::Config(ref e) => write!(fmt, "Configuration loading failed: {}", e),
Error::Core(ref e) => write!(fmt, "System creation failed: {}", e),
}
}
}
impl From<core::Error> for Error {
fn from(e: core::Error) -> Self {
Error::Core(e)
}
}
impl From<renderer::error::Error> for Error {
fn from(err: renderer::error::Error) -> Self {
Error::Core(core::Error::with_chain(err, "Renderer error"))
}
}