hexchat_api/errors.rs
1use std::error::Error;
2use std::fmt::{self, Display, Formatter};
3
4/// Each of the various ways the API can fail is collected in this enumerated
5/// type.
6///
7#[derive(Debug, Clone)]
8pub enum HexchatError {
9 /// The command failed to execute.
10 CommandFailed(String),
11
12 /// The requested info wasn't found or doesn't exist.
13 InfoNotFound(String),
14
15 /// This can happen when a `ThreadSafeContext` or `ThreadSafeListIterator`
16 /// object is used while the plugin is unloading. The main thread task
17 /// handler isn't accepting any more tasks, so the operation fails.
18 ThreadSafeOperationFailed(String),
19
20 /// The list iterator may return this if the Hexchat API changes. Currently
21 /// this won't get thrown.
22 UnknownType(String),
23
24 /// The function was unable to acquire the desired context associated with
25 /// the given network and channel names.
26 ContextAcquisitionFailed(String),
27
28 /// The context acquisition succeeded, but there is some problem with the
29 /// action being performed. For instance the requested list for
30 /// `ctx.get_listiter("foo")` doesn't exist.
31 ContextOperationFailed(String),
32
33 /// The context object was dropped.
34 ContextDropped(String),
35
36 /// The requested list doesn't exist.
37 ListNotFound(String),
38
39 /// The requested field doesn't exist.
40 ListFieldNotFound(String),
41
42 /// The list iterator type for Hexchat requires that next() be called at
43 /// least once before its fields are accessible.
44 ListIteratorNotStarted(String),
45
46 /// The list iterator object was dropped. This might happen if the plugin is
47 /// unloading while another thread is still running and using the iterator.
48 ListIteratorDropped(String),
49
50 /// The UserData cannot be cast to the specified type.
51 UserDataCastError(String),
52}
53
54unsafe impl Send for HexchatError {}
55
56impl Error for HexchatError {}
57
58impl Display for HexchatError {
59 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
60 let mut s = format!("{:?}", self);
61 s.retain(|c| c != '"');
62 write!(f, "{}", s)
63 }
64}