bornera_core/write/
error.rs1use core::fmt;
4
5use calandria::RetainedBytes;
6
7use crate::{ConnectionEpoch, EffectId};
8
9#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11#[non_exhaustive]
12pub enum WriteIdentityKind {
13 Operation,
15 Effect,
17}
18
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
21#[non_exhaustive]
22pub enum WriteAdmissionFailure {
23 StaleEpoch {
25 expected: ConnectionEpoch,
27 received: ConnectionEpoch,
29 },
30 IdentityInUse(WriteIdentityKind),
32 FrameCapacityReached {
34 limit: usize,
36 },
37 RetainedByteCapacity {
39 retained: RetainedBytes,
41 incoming: RetainedBytes,
43 limit: RetainedBytes,
45 },
46}
47
48#[derive(Clone, Debug, Eq, PartialEq)]
50pub(crate) struct WriteAdmissionError<F> {
51 failure: WriteAdmissionFailure,
52 frame: F,
53}
54
55impl<F> WriteAdmissionError<F> {
56 pub(crate) const fn new(failure: WriteAdmissionFailure, frame: F) -> Self {
57 Self { failure, frame }
58 }
59
60 pub(crate) const fn failure(&self) -> WriteAdmissionFailure {
62 self.failure
63 }
64
65 pub(crate) fn into_frame(self) -> F {
67 self.frame
68 }
69}
70
71impl<F> fmt::Display for WriteAdmissionError<F> {
72 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
73 self.failure.fmt(formatter)
74 }
75}
76
77impl<F: fmt::Debug> core::error::Error for WriteAdmissionError<F> {}
78
79impl fmt::Display for WriteAdmissionFailure {
80 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
81 formatter.write_str(match self {
82 Self::StaleEpoch { .. } => "frame belongs to another connection epoch",
83 Self::IdentityInUse(_) => "operation or effect identity is already queued",
84 Self::FrameCapacityReached { .. } => "write-frame capacity is exhausted",
85 Self::RetainedByteCapacity { .. } => "write retained-byte capacity is exhausted",
86 })
87 }
88}
89
90#[derive(Clone, Copy, Debug, Eq, PartialEq)]
92#[non_exhaustive]
93pub enum WriteProgressError {
94 StaleEpoch {
96 expected: ConnectionEpoch,
98 received: ConnectionEpoch,
100 },
101 NoPendingWrite,
103 OutOfOrderEffect {
105 expected: EffectId,
107 received: EffectId,
109 },
110 ExceedsRemaining {
112 written: usize,
114 remaining: usize,
116 },
117 ProgressAccountingOverflow {
119 measured: usize,
121 written: usize,
123 },
124 RetainedAccountingUnderflow {
126 retained: RetainedBytes,
128 released: RetainedBytes,
130 },
131}
132
133impl fmt::Display for WriteProgressError {
134 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
135 formatter.write_str(match self {
136 Self::StaleEpoch { .. } => "write progress belongs to another epoch",
137 Self::NoPendingWrite => "no ordered write is pending",
138 Self::OutOfOrderEffect { .. } => "write progress does not name the FIFO front",
139 Self::ExceedsRemaining { .. } => "write progress exceeds remaining frame bytes",
140 Self::ProgressAccountingOverflow { .. } => {
141 "write progress exceeded the committed frame measurement"
142 }
143 Self::RetainedAccountingUnderflow { .. } => {
144 "write retained-byte accounting underflowed"
145 }
146 })
147 }
148}
149
150impl core::error::Error for WriteProgressError {}