reifydb_core/error/diagnostic/
transaction.rs1use reifydb_type::{error::diagnostic::Diagnostic, fragment::Fragment};
5
6pub fn transaction_conflict() -> Diagnostic {
8 Diagnostic {
9 code: "TXN_001".to_string(),
10 statement: None,
11 message: "Transaction conflict detected - another transaction modified the same data".to_string(),
12 column: None,
13 fragment: Fragment::None,
14 label: None,
15 help: Some("Retry the transaction".to_string()),
16 notes: vec![],
17 cause: None,
18 operator_chain: None,
19 }
20}
21
22pub fn transaction_rolled_back() -> Diagnostic {
24 Diagnostic {
25 code: "TXN_002".to_string(),
26 statement: None,
27 message: "Transaction rolled back and cannot be committed".to_string(),
28 column: None,
29 fragment: Fragment::None,
30 label: None,
31 help: Some("Start a new transaction".to_string()),
32 notes: vec![],
33 cause: None,
34 operator_chain: None,
35 }
36}
37
38pub fn transaction_too_large() -> Diagnostic {
40 Diagnostic {
41 code: "TXN_003".to_string(),
42 statement: None,
43 message: "Transaction contains too many writes and exceeds size limits".to_string(),
44 column: None,
45 fragment: Fragment::None,
46 label: None,
47 help: Some("Split the transaction into smaller batches".to_string()),
48 notes: vec![],
49 cause: None,
50 operator_chain: None,
51 }
52}
53
54pub fn commit_failed(reason: String) -> Diagnostic {
56 Diagnostic {
57 code: "TXN_004".to_string(),
58 statement: None,
59 message: format!("Transaction commit failed: {}", reason),
60 column: None,
61 fragment: Fragment::None,
62 label: None,
63 help: Some("Check transaction state and retry if appropriate".to_string()),
64 notes: vec![],
65 cause: None,
66 operator_chain: None,
67 }
68}
69
70pub fn transaction_already_committed() -> Diagnostic {
72 Diagnostic {
73 code: "TXN_008".to_string(),
74 statement: None,
75 message: "Transaction was already committed".to_string(),
76 column: None,
77 fragment: Fragment::None,
78 label: None,
79 help: Some("Cannot use a transaction after it has been committed".to_string()),
80 notes: vec![],
81 cause: None,
82 operator_chain: None,
83 }
84}
85
86pub fn transaction_already_rolled_back() -> Diagnostic {
88 Diagnostic {
89 code: "TXN_009".to_string(),
90 statement: None,
91 message: "Transaction was already rolled back".to_string(),
92 column: None,
93 fragment: Fragment::None,
94 label: None,
95 help: Some("Cannot use a transaction after it has been rolled back".to_string()),
96 notes: vec![],
97 cause: None,
98 operator_chain: None,
99 }
100}
101
102pub fn key_out_of_scope(key: String) -> Diagnostic {
104 Diagnostic {
105 code: "TXN_010".to_string(),
106 statement: None,
107 message: format!("Key '{}' is not in the transaction's declared key scope", key),
108 column: None,
109 fragment: Fragment::None,
110 label: None,
111 help: Some("Declare the key when beginning the transaction or use a different transaction scope"
112 .to_string()),
113 notes: vec![],
114 cause: None,
115 operator_chain: None,
116 }
117}