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
//! The errors returned by the different operations in the library

/// Errors that can be returned for any command
#[derive(Copy, Clone, Debug, Eq, PartialEq, Fail)]
pub enum BeanstalkError {
    /// The client sent a command line that was not well-formed. This can happen if the line does not
    /// end with \r\n, if non-numeric characters occur where an integer is expected, if the wrong
    /// number of arguments are present, or if the command line is mal-formed in any other way.
    ///
    /// This should not happen, if it does please file an issue.
    #[fail(display = "Client command was not well formatted")]
    BadFormat,

    /// The server cannot allocate enough memory for the job. The client should try again later.
    #[fail(display = "Server out of memory")]
    OutOfMemory,

    /// This indicates a bug in the server. It should never happen. If it does happen, please report it
    /// at http://groups.google.com/group/beanstalk-talk.
    #[fail(display = "Internal server error")]
    InternalError,
    /// The client sent a command that the server does not know.
    ///
    /// This should not happen, if it does please file an issue.
    #[fail(display = "Unknown command sent by client")]
    UnknownCommand,

    #[fail(display = "An unexpected response occurred")]
    UnexpectedResponse,

    #[doc(hidden)]
    #[fail(display = "Just an extention..")]
    __Nonexhaustive,
}

/// Errors which can be casued due to a PUT command
#[derive(Copy, Clone, Debug, Eq, PartialEq, Fail)]
pub enum Put {
    /// The server ran out of memory trying to grow the priority queue data structure.
    /// The client should try another server or disconnect and try again later.
    #[fail(display = "Server had to bury the request")]
    Buried,

    /// The job body must be followed by a CR-LF pair, that is, "\r\n". These two bytes are not counted
    /// in the job size given by the client in the put command line.
    ///
    /// This should never happen, if it does please file an issue.
    #[fail(display = "CRLF missing from the end of command")]
    ExpectedCRLF,

    /// The client has requested to put a job with a body larger than max-job-size bytes
    #[fail(display = "Job size exceeds max-job-size bytes")]
    JobTooBig,

    /// This means that the server has been put into "drain mode" and is no longer accepting new jobs.
    /// The client should try another server or disconnect and try again later.
    #[fail(display = "Server is in drain mode")]
    Draining,

    #[fail(display = "A protocol error occurred: {}", error)]
    Beanstalk { error: BeanstalkError },

    #[doc(hidden)]
    #[fail(display = "Just an extention..")]
    __Nonexhaustive,
}

/// Errors which can occur when acting as a consumer/worker
#[derive(Copy, Clone, Debug, Eq, PartialEq, Fail)]
pub enum Consumer {
    /// If the job does not exist or is not either reserved by the client
    #[fail(display = "Did not find a job of that Id")]
    NotFound,
    /// if the server ran out of memory trying to grow the priority queue data structure.
    #[fail(display = "Job got buried")]
    Buried,
    /// If the client attempts to ignore the only tube in its watch list.
    #[fail(display = "Tried to ignore the only tube being watched")]
    NotIgnored,

    #[fail(display = "A protocol error occurred: {}", error)]
    Beanstalk { error: BeanstalkError },

    #[doc(hidden)]
    #[fail(display = "Just an extention..")]
    __Nonexhaustive,
}