1use thiserror::Error;
2
3#[derive(Clone, Debug, Error)]
4pub enum HatchetError {
5 #[error("missing required environment variable \"{0}\"")]
6 MissingEnvVar(String),
7 #[error("token should have three parts")]
8 InvalidTokenFormat,
9 #[error("{0}")]
10 Base64DecodeError(#[from] base64::DecodeError),
11 #[error("Error decoding JSON: {0}")]
12 JsonDecodeError(String),
13 #[error("Error encoding JSON: {0}")]
14 JsonEncode(String),
15 #[error("Missing required field in JWT payload: {0}")]
16 MissingTokenField(&'static str),
17 #[error("Invalid authorization header in gRPC request: {0}")]
18 InvalidAuthHeader(String),
19 #[error("Unable to connect to gRPC server: {0}")]
20 GrpcConnect(String),
21 #[error("Response missing output")]
22 MissingOutput,
23 #[error("{0}")]
24 WorkflowFailed(String),
25 #[error("workflow cancelled")]
26 WorkflowCancelled,
27 #[error("invalid gRPC URI: {0}")]
28 InvalidUri(String),
29 #[error("no tasks found in workflow")]
30 MissingTasks,
31 #[error("{0}")]
32 SystemTimeError(#[from] std::time::SystemTimeError),
33 #[error("unrecognized action received: {0}")]
34 UnrecognizedAction(String),
35 #[error("task not found: {task_name}")]
36 TaskNotFound { task_name: String },
37 #[error("Parent task not found: {parent_step_name}")]
38 ParentTaskNotFound { parent_step_name: String },
39 #[error("Invalid gRPC address: {0}")]
40 InvalidGrpcAddress(String),
41 #[error("Invalid TLS strategy: '{0}'. Valid options are 'none' or 'tls'")]
42 InvalidTlsStrategy(String),
43 #[error("gRPC request returned error: {0}")]
44 GrpcErrorStatus(String),
45 #[error("Error installing default crypto provider")]
46 CryptoProvider,
47 #[error("{0}")]
48 RestApiError(String),
49 #[error("Invalid cron expression: {0}")]
50 InvalidCronExpression(String),
51 #[error("Error sending message to dispatcher: {0}")]
52 DispatchError(String),
53 #[error("Error sending stream event: {0}")]
54 StreamError(String),
55 #[error("Internal error: {0}")]
56 InternalError(String),
57}
58
59impl HatchetError {
60 pub(crate) fn from_rest<E: std::fmt::Display>(error: E) -> Self {
61 Self::RestApiError(error.to_string())
62 }
63}