noxu_xa/error.rs
1//! XA error types.
2
3use crate::xid::XidError;
4
5/// XA errors returned from XaResource operations.
6#[derive(Debug, thiserror::Error)]
7pub enum XaError {
8 /// The XID is not valid or cannot be found.
9 #[error("XAER_NOTA: unknown XID")]
10 NotFound,
11
12 /// Invalid arguments passed.
13 #[error("XAER_INVAL: invalid arguments")]
14 Invalid,
15
16 /// Protocol error (operation called in wrong state).
17 #[error("XAER_PROTO: protocol error — {0}")]
18 Protocol(String),
19
20 /// Resource manager failure.
21 #[error("XAER_RMFAIL: resource manager failure — {0}")]
22 RmFail(String),
23
24 /// Duplicate XID.
25 #[error("XAER_DUPID: duplicate XID")]
26 DuplicateXid,
27
28 /// Work performed outside global transaction.
29 #[error("XAER_OUTSIDE: work outside global transaction")]
30 Outside,
31
32 /// Heuristic commit (TM should forget).
33 #[error("XA_HEURCOM: heuristic commit")]
34 HeuristicCommit,
35
36 /// Heuristic rollback (TM should forget).
37 #[error("XA_HEURRB: heuristic rollback")]
38 HeuristicRollback,
39
40 /// This variant is retained for SemVer
41 /// compatibility but is no longer returned by the engine. Crash-
42 /// durable XA is now supported — a `TxnPrepare` WAL frame is
43 /// written by `xa_prepare`, recovery surfaces in-doubt XIDs via
44 /// `xa_recover()`, and `xa_commit` / `xa_rollback` resolve them
45 /// against the recovered prepared list maintained on the
46 /// `EnvironmentImpl`.
47 ///
48 /// New code should not match on this variant. It will be removed
49 /// in v3.0.
50 ///
51 /// Use [`XaError::NotFound`] for genuinely unknown XIDs and
52 /// [`XaError::Protocol`] for state-machine violations.
53 #[deprecated(
54 since = "2.0.0",
55 note = "crash-durable XA is now supported (wave 3-2); this variant is no longer returned"
56 )]
57 #[error(
58 "XA crash durability is not supported: this variant is retained \
59 for SemVer compatibility and will be removed in v3.0."
60 )]
61 CrashDurabilityNotSupported,
62
63 /// Xid construction error.
64 #[error(transparent)]
65 Xid(#[from] XidError),
66
67 /// Underlying database error.
68 #[error("database error: {0}")]
69 Db(#[from] noxu_db::NoxuError),
70}
71
72/// XA result type.
73pub type XaResult<T> = Result<T, XaError>;
74
75/// Return value indicating the branch was read-only (no commit needed).
76#[derive(Debug, Clone, Copy, PartialEq, Eq)]
77pub enum PrepareResult {
78 /// Branch has modifications; commit or rollback required.
79 Ok,
80 /// Branch was read-only; no commit or rollback needed.
81 ReadOnly,
82}