Skip to main content

meerkat_workgraph/
error.rs

1use crate::types::{WorkAttentionBindingId, WorkItemId, WorkNamespace};
2
3#[derive(Debug, thiserror::Error)]
4pub enum WorkGraphError {
5    #[error("work item {id} not found in realm '{realm_id}' namespace '{namespace}'")]
6    NotFound {
7        realm_id: String,
8        namespace: WorkNamespace,
9        id: WorkItemId,
10    },
11    #[error(
12        "work attention binding {binding_id} not found in realm '{realm_id}' namespace '{namespace}'"
13    )]
14    AttentionNotFound {
15        realm_id: String,
16        namespace: WorkNamespace,
17        binding_id: WorkAttentionBindingId,
18    },
19    #[error("stale work item revision for {id}: expected {expected}, actual {actual}")]
20    StaleRevision {
21        id: WorkItemId,
22        expected: u64,
23        actual: u64,
24    },
25    #[error("conflicting work graph mutation: {0}")]
26    Conflict(String),
27    #[error("invalid work graph transition: {0}")]
28    InvalidTransition(String),
29    #[error("invalid work graph input: {0}")]
30    InvalidInput(String),
31    #[error("work graph timestamp `{field}` cannot be represented as unsigned millis: {millis}")]
32    InvalidTimestampMillis { field: &'static str, millis: i64 },
33    #[error("work graph store error: {0}")]
34    Store(String),
35    #[error("work graph backend '{0}' does not support this operation")]
36    UnsupportedBackend(String),
37}
38
39impl WorkGraphError {
40    pub fn not_found(realm_id: String, namespace: WorkNamespace, id: WorkItemId) -> Self {
41        Self::NotFound {
42            realm_id,
43            namespace,
44            id,
45        }
46    }
47
48    pub fn attention_not_found(
49        realm_id: String,
50        namespace: WorkNamespace,
51        binding_id: WorkAttentionBindingId,
52    ) -> Self {
53        Self::AttentionNotFound {
54            realm_id,
55            namespace,
56            binding_id,
57        }
58    }
59}