Skip to main content

worldinterface_contextstore/
error.rs

1//! Error types for ContextStore operations.
2
3use worldinterface_core::id::{FlowRunId, NodeId};
4
5/// Errors from ContextStore operations.
6#[derive(Debug, thiserror::Error)]
7pub enum ContextStoreError {
8    /// Attempted to write a key that already has a value.
9    /// This is expected during idempotent retries (Invariant 4).
10    #[error("output already exists for ({flow_run_id}, {node_id})")]
11    AlreadyExists { flow_run_id: FlowRunId, node_id: NodeId },
12
13    /// Attempted to write a global key that already has a value.
14    #[error("global key already exists: {key}")]
15    GlobalAlreadyExists { key: String },
16
17    /// The value could not be serialized to bytes for storage.
18    #[error("serialization failed: {0}")]
19    SerializationFailed(#[from] serde_json::Error),
20
21    /// The stored bytes could not be deserialized back to a Value.
22    #[error("deserialization failed: {source}")]
23    DeserializationFailed {
24        #[source]
25        source: serde_json::Error,
26    },
27
28    /// Underlying storage I/O error.
29    #[error("storage error: {0}")]
30    StorageError(String),
31}
32
33/// Errors from the atomic write-before-complete protocol.
34#[derive(Debug, thiserror::Error)]
35pub enum AtomicWriteError {
36    /// The ContextStore write failed (non-idempotent failure).
37    #[error("context store write failed: {0}")]
38    WriteFailed(ContextStoreError),
39
40    /// The write succeeded but the completion callback failed.
41    /// The output IS durable — on retry, the write will return AlreadyExists
42    /// and completion will be re-attempted.
43    #[error("completion failed after successful write: {0}")]
44    CompletionFailed(Box<dyn std::error::Error + Send + Sync>),
45}