Skip to main content

oxideav_dvd/
error.rs

1//! Crate-local error type.
2//!
3//! Kept deliberately small and `oxideav-core`-free so the standalone
4//! build path stays decoupled from the framework error type. A small
5//! `From<std::io::Error>` lets `?` work over the disc I/O layer.
6
7use std::fmt;
8
9/// Result alias for the crate.
10pub type Result<T> = std::result::Result<T, Error>;
11
12/// What can go wrong when mounting a DVD or walking its file system.
13#[derive(Debug)]
14pub enum Error {
15    /// Underlying I/O error (sector read, file open).
16    Io(std::io::Error),
17    /// An ISO 9660 structure (PVD, directory record, path table) is
18    /// malformed or violates the spec's invariants.
19    InvalidIso9660(&'static str),
20    /// A UDF descriptor (tag, AVDP, VDS member, FSD, FID, FE) is
21    /// malformed or violates the spec's invariants.
22    InvalidUdf(&'static str),
23    /// The disc image looks like a valid optical disc but isn't a
24    /// DVD-Video disc (no `VIDEO_TS/` directory, or `VIDEO_TS/` is
25    /// present but `VIDEO_TS.IFO` is absent).
26    NotDvdVideo(&'static str),
27}
28
29impl fmt::Display for Error {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            Self::Io(e) => write!(f, "I/O error: {e}"),
33            Self::InvalidIso9660(s) => write!(f, "invalid ISO 9660 structure: {s}"),
34            Self::InvalidUdf(s) => write!(f, "invalid UDF structure: {s}"),
35            Self::NotDvdVideo(s) => write!(f, "not a DVD-Video disc: {s}"),
36        }
37    }
38}
39
40impl std::error::Error for Error {
41    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
42        match self {
43            Self::Io(e) => Some(e),
44            _ => None,
45        }
46    }
47}
48
49impl From<std::io::Error> for Error {
50    fn from(e: std::io::Error) -> Self {
51        Self::Io(e)
52    }
53}