zeebe/
error.rs

1use std::io;
2use tonic::transport;
3
4/// The result type returned by zeebe methods.
5pub type Result<T> = std::result::Result<T, Error>;
6
7/// The error type which is returned from zeebe processing failures.
8///
9/// The gRPC API for Zeebe is exposed through the gateway, which acts as a proxy
10/// for the broker. Generally, this means that the client executes an remote
11/// call on the gateway, which is then translated to special binary protocol
12/// that the gateway uses to communicate with the broker.
13///
14/// As a result of this proxying, any errors which occur between the gateway and
15/// the broker for which the client is not at fault (e.g. the gateway cannot
16/// deserialize the broker response, the broker is unavailable, etc.) are
17/// reported to the client using the following error codes.
18///
19/// * `GRPC_STATUS_RESOURCE_EXHAUSTED`: if the broker is receiving too many
20///   requests more than what it can handle, it kicks off back-pressure and
21///   rejects requests with this error code. In this case, it is possible to retry
22///   the requests with an appropriate retry strategy. If you receive many such
23///   errors with in a small time period, it indicates that the broker is
24///   constantly under high load. It is recommended to reduce the rate of
25///   requests. When the back-pressure kicks off, the broker may reject any
26///   request except CompleteJob RPC and FailJob RPC. These requests are
27///   white-listed for back-pressure and are always accepted by the broker even if
28///   it is receiving requests above its limits.
29/// * `GRPC_STATUS_UNAVAILABLE`: if the gateway itself is in an invalid state
30///   (e.g. out of memory)
31/// * `GRPC_STATUS_INTERNAL`: for any other internal errors that occurred between
32///   the gateway and the broker.
33///
34/// This behavior applies to every single possible RPC; in these cases, it is possible that
35/// retrying would succeed, but it is recommended to do so with an appropriate retry policy (e.g. a
36/// combination of exponential backoff or jitter wrapped in a circuit breaker).
37///
38/// In the documentation below, the documented errors are business logic errors, meaning errors
39/// which are a result of request processing logic, and not serialization, network, or other more
40/// general errors.
41#[derive(thiserror::Error, Debug)]
42pub enum Error {
43    /// Error returned from invalid client gateway configuration.
44    #[error("invalid gateway uri '{uri:?}': {message:?}")]
45    InvalidGatewayUri {
46        /// The error message.
47        message: String,
48        /// The invalid uri argument.
49        uri: String,
50    },
51    /// GRPC transport errors.
52    #[error(transparent)]
53    Transport(#[from] transport::Error),
54    /// GRPC result errors
55    #[error(transparent)]
56    GRPC(#[from] tonic::Status),
57    /// File I/O errors when reading processes from disk.
58    #[error("Invalid resource file {resource_file:?}: {source:?}")]
59    FileIo {
60        /// The specified resource file
61        resource_file: String,
62        /// The underlying `io::Error`.
63        source: io::Error,
64    },
65    /// Invalid method parameters
66    #[error("Invalid parameters: {0}")]
67    InvalidParameters(&'static str),
68    /// Job payload deserialization error
69    #[error("Cannot deserialize variables to expected type: {0}")]
70    DeserializationError(#[from] serde_json::Error),
71    /// Missing worker state configuration
72    #[error("Worker state is not configured, use `JobWorkerBuilder::with_state` while building worker for this job")]
73    MissingWorkerStateConfig,
74    /// Authentication errors
75    #[error("Could not authenticate: {0}")]
76    Auth(String),
77}