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
66
67
68
69
70
71
72
73
74
75
76
77
78
#![allow(renamed_and_removed_lints)]
use std::fmt;
use types::TaskId;
use utils::convert::ToCapnp;
error_chain!{
types {
Error, ErrorKind, ResultExt;
}
foreign_links {
Io(::std::io::Error);
Capnp(::capnp::Error);
CapnpNotInSchema(::capnp::NotInSchema);
Timer(::tokio_timer::Error);
SessionErr(SessionError);
Utf8Err(::std::str::Utf8Error);
Json(::serde_json::Error);
Sqlite(::rusqlite::Error);
}
errors {
Ignored {
description("Request asked for ignored id")
}
}
}
pub type Result<T> = ::std::result::Result<T, Error>;
impl ::std::convert::From<Error> for ::capnp::Error {
fn from(e: Error) -> Self {
::capnp::Error::failed(e.description().to_string())
}
}
#[derive(Debug, Clone)]
pub struct SessionError {
message: String,
debug: String,
task_id: TaskId,
}
impl SessionError {
pub fn new(message: String, debug: String, task_id: TaskId) -> Self {
SessionError {
message,
debug,
task_id,
}
}
pub fn to_capnp(&self, builder: &mut ::common_capnp::error::Builder) {
builder.reborrow().set_message(&self.message);
builder.reborrow().set_debug(&self.debug);
self.task_id
.to_capnp(&mut builder.reborrow().get_task().unwrap());
}
}
impl ::std::error::Error for SessionError {
fn description(&self) -> &str {
&self.message
}
fn cause(&self) -> Option<&::std::error::Error> {
None
}
}
impl fmt::Display for SessionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SessionError({:?})", self.message)
}
}