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