1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::fmt::Debug;
use std::io;
use std::string::FromUtf8Error;

use thiserror::Error;

use crate::Entry;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
pub enum Error {
    #[error("{0}")]
    Io(#[from] io::Error),
    #[error("Invalid base directory")]
    InvalidBaseDir,
    #[error("{0}")]
    WalkDir(#[from] walkdir::Error),
    #[error("Unknown compressor (name or level)")]
    InvalidCompressor,
    #[error("Invalid file type")]
    InvalidFileType,
    #[error("Invalid entry header")]
    InvalidEntryHeader,
    #[error("Unknown file type")]
    UnknownFileType,
    #[error("Unknown compression method")]
    UnknownCompressionMethod,
    #[error("Checksum error for entry: {0:?}")]
    Checksum(Entry),
    #[cfg(unix)]
    #[error("Unix errno: {0}")]
    Errno(#[from] nix::Error),
    #[error("External compressor non-zero exit code: {0}")]
    FilterNonZeroExit(i32),
    #[error("External decompressor not provided")]
    MissingDecompressor,
    #[error("Only use relative paths")]
    AbsolutePath,
    #[error("{0}")]
    FromUtf8(#[from] FromUtf8Error),
    #[error("Invalid info json")]
    InvalidInfoJson,
    #[error("Invalid time")]
    InvalidTime(TimeError),
    #[error("Error from compressor: {0}")]
    CompressorError(String),
    #[error("Error from decompressor: {0}")]
    DecompressorError(String),
    #[error("{0}")]
    Others(String),
}

#[derive(Error, Debug)]
pub enum TimeError {
    #[error("No such local time")]
    None,
    #[error("Ambiguous local time, range: {0:?}")]
    Ambiguous(String),
}

impl From<&str> for Error {
    fn from(msg: &str) -> Self {
        Self::Others(msg.into())
    }
}