cfg_noodle/error.rs
1//! Error types used for the list
2use crate::{logging::MaybeDefmtFormat, storage_node::State};
3
4/// General error that is not specific to the flash implementation
5#[derive(Debug, PartialEq)]
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7pub enum Error {
8 /// Deserializing node from the buffer failed
9 Deserialization,
10 /// Serializing a node into the buffer failed because the buffer was too small
11 Serialization,
12 /// The key already exists in the list
13 DuplicateKey,
14 /// Recoverable error to tell the caller that the list needs reading first.
15 NeedsFirstRead,
16 /// Recoverable error to tell the caller that the list needs to process garbage
17 /// collection before doing writes. In some cases, this might not be necessary,
18 /// but for now we force it after the first read and after every write to avoid
19 /// running out of space.
20 NeedsGarbageCollect,
21 /// Node is in a state that is invalid at the particular point of operation.
22 /// Contains a tuple of the node key and the state that was deemed invalid.
23 InvalidState(&'static str, State),
24 /// The flash returned inconsistent data between iterations. This is likely fatal.
25 InconsistentFlash,
26 /// Tried to create a Node Handle when one already exists for a given node
27 AlreadyTaken,
28 /// Node exists in another list already and needs to be detached
29 NodeInOtherList,
30}
31
32#[derive(Debug, PartialEq)]
33#[cfg_attr(feature = "defmt", derive(defmt::Format))]
34/// Errors during loading from and storing to flash.
35///
36/// Sometimes specific to the flash implementation.
37pub enum LoadStoreError<T: MaybeDefmtFormat> {
38 /// Writing to flash has failed. Contains the error returned by the storage impl.
39 FlashWrite(T),
40 /// Reading from flash has failed. Contains the error returned by the storage impl.
41 FlashRead(T),
42 /// Buffer size wrong
43 InvalidBufferSize,
44 /// Value read back from the flash during verification did not match serialized list node.
45 WriteVerificationFailed,
46 /// Application-level error that occurred during list operations.
47 AppError(Error),
48}
49
50impl<T: MaybeDefmtFormat> From<Error> for LoadStoreError<T> {
51 fn from(value: Error) -> Self {
52 Self::AppError(value)
53 }
54}