Skip to main content

tig_core/
err.rs

1//! ライブラリ全体で共有するエラー型。
2
3use core::fmt;
4
5/// 解析・検証の失敗。入力データの破損や未対応形式を表す。
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Error {
8    /// 入力が途中で尽きた。
9    UnexpectedEof,
10    /// 形式違反。値は違反箇所の簡潔な説明。
11    Corrupt(&'static str),
12    /// SHA-256 repository 等、未対応の形式。値は形式の名前。
13    Unsupported(&'static str),
14    /// checksum (adler32 / SHA-1) の不一致。値は対象の名前。
15    Checksum(&'static str),
16    /// delta の base object が見つからない。
17    MissingBase,
18}
19
20impl fmt::Display for Error {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        match self {
23            Error::UnexpectedEof => write!(f, "unexpected end of input"),
24            Error::Corrupt(what) => write!(f, "corrupt data: {what}"),
25            Error::Unsupported(what) => write!(f, "unsupported: {what}"),
26            Error::Checksum(what) => write!(f, "checksum mismatch: {what}"),
27            Error::MissingBase => write!(f, "delta base object not found"),
28        }
29    }
30}
31
32impl core::error::Error for Error {}
33
34pub type Result<T> = core::result::Result<T, Error>;