exfat/
error.rs

1use displaydoc::Display;
2use thiserror::Error;
3
4#[derive(Debug, Display)]
5pub enum DataError {
6    /// Not exFAT filesystem
7    NotExFAT,
8    /// Bad boot sector checksum
9    BootChecksum,
10    /// Allocation bitmap missing
11    AllocationBitmapMissing,
12    /// Upcase table missing
13    UpcaseTableMissing,
14    /// Bad upcase table checksum
15    UpcaseTableChecksum,
16    /// Broken FAT chain
17    FATChain,
18    /// Broken file or directory metadata
19    Metadata,
20}
21
22impl core::error::Error for DataError {}
23
24#[derive(Debug, Display)]
25pub enum ImplementationError {
26    /// TexFAT not supported
27    TexFATNotSupported,
28    /// Create directory not supported
29    CreateDirectoryNotSupported,
30}
31
32impl core::error::Error for ImplementationError {}
33
34#[derive(Debug, Display)]
35pub enum InputError {
36    /// Name too long
37    NameTooLong,
38    /// Seek position out of range
39    SeekPosition,
40    /// Size out of range
41    Size,
42}
43
44impl core::error::Error for InputError {}
45
46#[derive(Debug, Display)]
47pub enum AllocationError {
48    /// Allocation-not-possible is set in file metadata
49    NotPossible,
50    /// Need fragment while dont-fragment is set in file options
51    Fragment,
52    /// No more cluster available
53    NoMoreCluster,
54}
55
56impl core::error::Error for AllocationError {}
57
58#[derive(Debug, Display)]
59pub enum OperationError {
60    /// File or directory already open
61    AlreadyOpen,
62    /// File or directory not found
63    NotFound,
64    /// Not a file
65    NotFile,
66    /// Not a directory
67    NotDirectory,
68    /// File or directory already exists
69    AlreadyExists,
70    /// Directory not empty when deleting
71    DirectoryNotEmpty,
72    /// End of file
73    EOF,
74}
75
76impl core::error::Error for OperationError {}
77
78#[derive(Error, Debug)]
79pub enum Error<E> {
80    #[error("IO({0:?})")]
81    IO(E),
82    #[error("{0:?}")]
83    Data(#[from] DataError),
84    #[error("{0:?}")]
85    Implementation(#[from] ImplementationError),
86    #[error("{0:?}")]
87    Input(#[from] InputError),
88    #[error("{0:?}")]
89    Operation(#[from] OperationError),
90    #[error("{0:?}")]
91    Allocation(#[from] AllocationError),
92}