runtara_sdk/
error.rs

1// Copyright (C) 2025 SyncMyOrders Sp. z o.o.
2// SPDX-License-Identifier: AGPL-3.0-or-later
3//! SDK-specific error types.
4
5use runtara_protocol::ClientError;
6use thiserror::Error;
7
8/// Errors that can occur in the SDK.
9#[derive(Debug, Error)]
10pub enum SdkError {
11    /// Configuration error (missing or invalid environment variable)
12    #[error("configuration error: {0}")]
13    Config(String),
14
15    /// Connection to runtara-core failed
16    #[error("connection error: {0}")]
17    Connection(#[from] ClientError),
18
19    /// Registration with runtara-core failed
20    #[error("registration failed: {0}")]
21    Registration(String),
22
23    /// Checkpoint operation failed
24    #[error("checkpoint error: {0}")]
25    Checkpoint(String),
26
27    /// Sleep request failed
28    #[error("sleep error: {0}")]
29    Sleep(String),
30
31    /// Event sending failed
32    #[error("event error: {0}")]
33    Event(String),
34
35    /// Signal error
36    #[error("signal error: {0}")]
37    Signal(String),
38
39    /// Status query failed
40    #[error("status error: {0}")]
41    Status(String),
42
43    /// Server returned an error response
44    #[error("server error: {code} - {message}")]
45    Server {
46        /// Error code from the server
47        code: String,
48        /// Error message from the server
49        message: String,
50    },
51
52    /// Instance was cancelled
53    #[error("instance cancelled")]
54    Cancelled,
55
56    /// Instance was paused
57    #[error("instance paused")]
58    Paused,
59
60    /// Serialization/deserialization error
61    #[error("serialization error: {0}")]
62    Serialization(String),
63
64    /// Unexpected response from server
65    #[error("unexpected response: {0}")]
66    UnexpectedResponse(String),
67}
68
69impl From<prost::DecodeError> for SdkError {
70    fn from(err: prost::DecodeError) -> Self {
71        SdkError::Serialization(err.to_string())
72    }
73}
74
75/// Type alias for SDK results.
76pub type Result<T> = std::result::Result<T, SdkError>;