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
84
85
86
87
//! Errors that can be returned by the library
use actix::MailboxError;
use std::io;
use tokio::timer;

/// Enum wrapping all possible errors that can be generated by the library
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Wraps actix's `MailboxError` error
    #[error("internal gWasm API error: {0}")]
    MailboxError(#[from] MailboxError),

    /// Wraps tokio's `timer::Error` error
    #[error("internal gWasm API error: {0}")]
    TimerError(#[from] timer::Error),

    /// Wraps libstd's `std::io::Error` error
    #[error("internal gWasm API error: {0}")]
    IOError(#[from] io::Error),

    /// Wraps Golem's `actix_wamp::Error` error
    #[error("internal Golem error: {0}")]
    WampError(actix_wamp::Error),

    /// Wraps Golem RPC's `golem_rpc_api::Error` error
    #[error("internal Golem error: {0}")]
    GolemRPCError(golem_rpc_api::Error),

    /// Wraps `tokio_ctrlc_error::KeyboardInterrupt` which is used to handle
    /// Ctrl-C interrupt event for the lib's client
    #[error("received Ctrl-C interrupt")]
    KeyboardInterrupt(tokio_ctrlc_error::KeyboardInterrupt),

    /// Wraps other `tokio_ctrlc_error::IoError` type errors
    #[error("internal gWasm API error: {0}")]
    CtrlcError(tokio_ctrlc_error::IoError),

    /// Wraps `chrono::ParseError` error
    #[error("error parsing Timeout value: {0}")]
    ChronoError(#[from] chrono::ParseError),

    /// Error generated when trying to create a zero [`Timeout`](../timeout/struct.Timeout.html)
    /// value for a Golem Task
    #[error("zero timeout \"00:00:00\" is forbidden")]
    ZeroTimeoutError,

    /// Error when no TaskInfo is received when polling for task progress
    /// in [`poll_task_progress`](../golem/fn.poll_task_progress.html)
    #[error("empty TaskInfo received from Golem")]
    EmptyTaskInfo,

    /// Error when no progress can be extracted from TaskInfo
    #[error("empty progress in TaskInfo")]
    EmptyProgress,

    /// Error when gWasm task was aborted externally
    #[error("task aborted externally")]
    TaskAborted,

    /// Error when gWasm task timed out
    #[error("task timed out")]
    TaskTimedOut,
}

impl From<actix_wamp::Error> for Error {
    fn from(err: actix_wamp::Error) -> Self {
        Error::WampError(err)
    }
}

impl From<golem_rpc_api::Error> for Error {
    fn from(err: golem_rpc_api::Error) -> Self {
        Error::GolemRPCError(err)
    }
}

impl From<tokio_ctrlc_error::IoError> for Error {
    fn from(err: tokio_ctrlc_error::IoError) -> Self {
        Error::CtrlcError(err)
    }
}

impl From<tokio_ctrlc_error::KeyboardInterrupt> for Error {
    fn from(err: tokio_ctrlc_error::KeyboardInterrupt) -> Self {
        Error::KeyboardInterrupt(err)
    }
}