pf8/
error.rs

1//! Error types for the PF8 library.
2
3use std::io;
4use std::string::FromUtf8Error;
5
6/// A specialized `Result` type for PF8 operations.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// The error type for PF8 operations.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// I/O error occurred.
13    #[error("I/O error: {0}")]
14    Io(io::Error),
15    /// Invalid PF8 file format.
16    #[error("Invalid PF8 format: {0}")]
17    InvalidFormat(String),
18    /// File not found in archive.
19    #[error("File not found in archive: {0}")]
20    FileNotFound(String),
21    /// Invalid UTF-8 in file names.
22    #[error("Invalid UTF-8 in file name: {0}")]
23    InvalidUtf8(FromUtf8Error),
24    /// Encryption/decryption error.
25    #[error("Encryption/decryption error: {0}")]
26    Crypto(String),
27    /// Archive is corrupted.
28    #[error("Archive is corrupted: {0}")]
29    Corrupted(String),
30    /// Operation was cancelled.
31    #[error("Operation was cancelled")]
32    Cancelled,
33}
34
35impl From<io::Error> for Error {
36    fn from(err: io::Error) -> Self {
37        Error::Io(err)
38    }
39}
40
41impl From<FromUtf8Error> for Error {
42    fn from(err: FromUtf8Error) -> Self {
43        Error::InvalidUtf8(err)
44    }
45}
46
47impl From<walkdir::Error> for Error {
48    fn from(err: walkdir::Error) -> Self {
49        Error::Io(err.into())
50    }
51}