1use super::ModuleFeatureInfo;
2use super::ModuleInfo;
3use super::ServerId;
4use irc;
5use rand;
6use serde_yaml;
7use std::any::Any;
8use std::borrow::Cow;
9use std::io;
10use util;
11
12error_chain! {
13 foreign_links {
14 Io(io::Error);
15
16 Rand(rand::Error);
17
18 SerdeYaml(serde_yaml::Error);
19 }
20
21 links {
22 YamlUtil(util::yaml::Error, util::yaml::ErrorKind);
23 }
24
25 errors {
26 IrcCrate(inner: irc::error::IrcError) {
29 description("IRC error")
30 display("IRC error: {}", inner)
31 }
32
33 ModuleRegistryClash(old: ModuleInfo, new: ModuleInfo) {
34 description("module registry clash")
35 display("Failed to load a new module because it would have overwritten an old module. \
36 Old: {:?}; new: {:?}.",
37 old,
38 new)
39 }
40
41 ModuleFeatureRegistryClash(old: ModuleFeatureInfo, new: ModuleFeatureInfo) {
42 description("module feature registry clash")
43 display("Failed to load a new module feature because it would have overwritten an old \
44 module feature. Old: {:?}; new: {:?}.",
45 old,
46 new)
47 }
48
49 ServerRegistryClash(server_id: ServerId) {
50 description("server registry UUID clash")
51 display("Failed to register a server because an existing server had the same UUID: \
52 {uuid}",
53 uuid = server_id.uuid.hyphenated())
54 }
55
56 Config(key: String, problem: String) {
57 description("configuration error")
58 display("Configuration error: Key {:?} {}.", key, problem)
59 }
60
61 ThreadSpawnFailure(io_err: io::Error) {
62 description("failed to spawn thread")
63 display("Failed to spawn thread: {}", io_err)
64 }
65
66 HandlerPanic(
67 feature_kind: Cow<'static, str>,
68 feature_name: Cow<'static, str>,
69 payload: Box<Any + Send + 'static>
70 ) {
71 description("panic in module feature handler function")
72 display("The handler function for {} {:?} panicked with the following message: {}",
73 feature_kind,
74 feature_name,
75 util::fmt::FmtAny(payload.as_ref()))
76 }
77
78 NicknameUnknown {
79 description("nickname retrieval error")
80 display("Puzzlingly, the bot seems to have forgotten its own nickname.")
81 }
82
83 UnknownServer(server_id: ServerId) {
84 description("server ID not recognized")
85 display("An attempt to look up a server connection or metadatum thereof failed, \
86 because the given server identification token (UUID {id}) was not a valid \
87 key in the relevant associative array.",
88 id = server_id.uuid.hyphenated())
89 }
90
91 LockPoisoned(lock_contents_desc: Cow<'static, str>) {
92 description("lock poisoned")
93 display("A thread panicked, poisoning a lock around {}.", lock_contents_desc)
94 }
95
96 Any(inner: Box<Any + Send + 'static>) {
97 description("miscellaneous error")
98 display("Error: {}", util::fmt::FmtAny(inner.as_ref()))
99 }
100
101 Unit {
102 description("unknown error")
103 display("An error seems to have occurred, but unfortunately the error type provided \
104 was the unit type, containing no information about the error.")
105 }
106 }
107}
108
109impl From<irc::error::IrcError> for Error {
110 fn from(orig: irc::error::IrcError) -> Self {
111 ErrorKind::IrcCrate(orig).into()
112 }
113}