fat/error.rs
1//! Error type for the FAT/exFAT reader.
2//!
3//! A *bootstrap* failure (unrecognized/invalid boot sector, unreadable
4//! prerequisite) surfaces loud as an error carrying the offending value; a
5//! per-node miss (a name not found) is a normal `Ok(None)`, never an error.
6
7use std::io;
8
9/// Errors raised while opening or navigating a FAT/exFAT volume.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum FatError {
13 /// Underlying reader failed during the named operation.
14 #[error("I/O error during {op}: {source}")]
15 Io {
16 /// The operation being attempted (e.g. `"read boot sector"`).
17 op: &'static str,
18 /// The originating I/O error.
19 source: io::Error,
20 },
21
22 /// The boot sector is structurally invalid; the message names the offending
23 /// field and value (fail-loud, show-the-value).
24 #[error("invalid boot sector: {0}")]
25 InvalidBoot(String),
26
27 /// The volume is not a recognized FAT or exFAT filesystem; the message
28 /// carries the bytes/signature that were found instead.
29 #[error("not a FAT/exFAT volume: {0}")]
30 NotFat(String),
31
32 /// A structure was internally inconsistent while navigating.
33 #[error("corrupt structure: {0}")]
34 Corrupt(String),
35}
36
37impl FatError {
38 /// Wrap an I/O error with the operation label. Public so downstream
39 /// analyzers can surface their own reads as typed `FatError`s.
40 #[must_use]
41 pub fn io(op: &'static str, source: io::Error) -> Self {
42 FatError::Io { op, source }
43 }
44}
45
46/// Convenience alias.
47pub type Result<T> = std::result::Result<T, FatError>;