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
79
80
81
82
83
use actix::MailboxError;
use std::io;
use std::path::{Path, PathBuf};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("internal gWasm API error: {0}")]
MailboxError(#[from] MailboxError),
#[error("gWasm API error: {0}")]
IOError(#[from] io::Error),
#[error("gWasm API error: {1}: {0}")]
FileError(io::Error, PathBuf),
#[error("internal Golem error: {0}")]
WampError(actix_wamp::Error),
#[error("internal Golem error: {0}")]
GolemRPCError(golem_rpc_api::Error),
#[error("error parsing Timeout value: {0}")]
ChronoError(#[from] chrono::ParseError),
#[error("received Ctrl-C interrupt")]
KeyboardInterrupt,
#[error("zero timeout \"00:00:00\" is forbidden")]
ZeroTimeoutError,
#[error("empty TaskInfo received from Golem")]
EmptyTaskInfo,
#[error("empty progress in TaskInfo")]
EmptyProgress,
#[error("task aborted externally")]
TaskAborted,
#[error("task timed out")]
TaskTimedOut,
}
impl From<actix_wamp::Error> for Error {
fn from(err: actix_wamp::Error) -> Self {
Self::WampError(err)
}
}
impl From<golem_rpc_api::Error> for Error {
fn from(err: golem_rpc_api::Error) -> Self {
Self::GolemRPCError(err)
}
}
pub(crate) trait FileContext<T, P> {
fn file_context(self, path: P) -> Result<T>;
}
impl<T, P: AsRef<Path>> FileContext<T, P> for io::Result<T> {
fn file_context(self, path: P) -> Result<T> {
self.map_err(|e| Error::FileError(e, path.as_ref().to_owned()))
}
}