Skip to main content

photon_backend/
error.rs

1//! Error types for Photon.
2
3use thiserror::Error;
4
5/// Result type alias for Photon operations.
6pub type Result<T> = std::result::Result<T, PhotonError>;
7
8/// Errors that can occur in Photon operations.
9#[derive(Debug, Clone, Error)]
10pub enum PhotonError {
11    /// Topic not found in registry.
12    #[error("topic not found: {0}")]
13    TopicNotFound(String),
14
15    /// Subscription not found.
16    #[error("subscription not found: {0}")]
17    SubscriptionNotFound(String),
18
19    /// Event not found.
20    #[error("event not found: {0}")]
21    EventNotFound(String),
22
23    /// Invalid topic name.
24    #[error("invalid topic name: {0}")]
25    InvalidTopicName(String),
26
27    /// Payload serialization/deserialization error.
28    #[error("payload error: {0}")]
29    PayloadError(String),
30
31    /// Schema mismatch at publish time.
32    #[error("schema mismatch: {0}")]
33    SchemaMismatch(String),
34
35    /// Topic already registered with different schema.
36    #[error("topic already exists: {0}")]
37    TopicAlreadyExists(String),
38
39    /// Subscription name required for durable subscriptions.
40    #[error("subscription name required for durable subscriptions")]
41    SubscriptionNameRequired,
42
43    /// Persistence / store error (ops metadata adapters).
44    #[error("persistence error: {0}")]
45    PersistenceError(String),
46
47    /// Identity reconstruction failed at the handler boundary.
48    ///
49    /// Produced when [`photon_core::IdentityFactory::reconstruct`] rejects actor JSON
50    /// (or a typed-actor downcast fails). Executor maps this to
51    /// [`crate::instrumentation::FailureReason::IdentityBuild`].
52    #[error("identity error: {0}")]
53    Identity(String),
54
55    /// Internal error.
56    #[error("internal error: {0}")]
57    Internal(String),
58}
59
60impl From<serde_json::Error> for PhotonError {
61    fn from(err: serde_json::Error) -> Self {
62        Self::PayloadError(err.to_string())
63    }
64}
65
66impl From<anyhow::Error> for PhotonError {
67    fn from(err: anyhow::Error) -> Self {
68        Self::Internal(err.to_string())
69    }
70}