esp_nvs/error.rs
1use crate::raw;
2use thiserror::Error;
3
4pub use raw::ItemType;
5
6/// Errors that can occur during NVS operations. The list is likely to stay as is but marked as
7/// non-exhaustive to allow for future additions without breaking the API. A caller would likely only
8/// need to handle NamespaceNotFound and KeyNotFound as the other errors are static.
9#[derive(Error, Debug, PartialEq)]
10#[cfg_attr(feature = "defmt", derive(defmt::Format))]
11#[non_exhaustive]
12pub enum Error {
13 /// The partition offset has to be aligned to the size of a flash sector (4k)
14 #[error("invalid partition offset")]
15 InvalidPartitionOffset,
16
17 /// The partition size has to be a multiple of the flash sector size (4k)
18 #[error("invalid partition size")]
19 InvalidPartitionSize,
20
21 /// The internal error value is returned from the provided `&mut impl flash::Flash`
22 #[error("internal flash error")]
23 FlashError,
24
25 /// Namespace not found. Either the flash was corrupted and silently fixed on
26 /// startup or no value has been written yet.
27 #[error("namespace not found")]
28 NamespaceNotFound,
29
30 /// The max namespace length is 15 bytes plus null terminator.
31 #[error("namespace too long")]
32 NamespaceTooLong,
33
34 /// The namespace is malformed. The last byte must be b'\0'
35 #[error("namespace malformed")]
36 NamespaceMalformed,
37
38 /// Strings are limited to `MAX_BLOB_DATA_PER_PAGE` while blobs can be up to `MAX_BLOB_SIZE` bytes
39 #[error("value too long")]
40 ValueTooLong,
41
42 /// The key is malformed. The last byte must be b'\0'
43 #[error("key malformed")]
44 KeyMalformed,
45
46 /// The max key length is 15 bytes plus null terminator.
47 #[error("key too long")]
48 KeyTooLong,
49
50 /// Key not found. Either the flash was corrupted and silently fixed on or no value has been written yet.
51 #[error("key not found")]
52 KeyNotFound,
53
54 /// The encountered item type is reported
55 #[error("item type mismatch: {0}")]
56 ItemTypeMismatch(ItemType),
57
58 /// Blob data is corrupted or inconsistent
59 #[error("corrupted data")]
60 CorruptedData,
61
62 /// Flash is full and defragmentation doesn't help.
63 #[error("flash full")]
64 FlashFull,
65
66 /// Used internally to indicate that we have to allocate a new page.
67 #[error("page full")]
68 PageFull,
69}