alpm_pkginfo/
error.rs

1use std::{path::PathBuf, string::FromUtf8Error};
2
3/// The Error that can occur when working with PKGINFO files
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7    /// ALPM type error
8    #[error("ALPM type parse error: {0}")]
9    AlpmType(#[from] alpm_types::Error),
10
11    /// IO error
12    #[error("I/O error at path {0:?} while {1}:\n{2}")]
13    IoPathError(PathBuf, &'static str, std::io::Error),
14
15    /// I/O error while reading a buffer.
16    #[error("Read error while {context}:\n{source}")]
17    IoReadError {
18        /// The context in which the error occurred.
19        ///
20        /// This is meant to complete the sentence "Read error while ".
21        context: &'static str,
22        /// The error source.
23        source: std::io::Error,
24    },
25
26    /// UTF-8 parse error
27    #[error(transparent)]
28    InvalidUTF8(#[from] FromUtf8Error),
29
30    /// An [`alpm_parsers::custom_ini::Error`].
31    #[error("Failed to deserialize PKGINFO file:\n{0}")]
32    DeserializeError(#[from] alpm_parsers::custom_ini::Error),
33
34    /// An extra data field specified without any value.
35    #[error("Extra data field is specified without any value")]
36    ExtraDataEmpty,
37
38    /// The first extra data field does not specify "pkgtype".
39    #[error("The first extra data definition does not specify \"pkgtype\"")]
40    FirstExtraDataNotPkgType,
41
42    /// No input file given
43    #[error("No input file given.")]
44    NoInputFile,
45
46    /// JSON error
47    #[error("JSON error: {0}")]
48    Json(#[from] serde_json::Error),
49
50    /// An invalid enum variant
51    #[error("Invalid variant ({0})")]
52    InvalidVariant(#[from] strum::ParseError),
53
54    /// Extra data is missing
55    #[error("Extra data is missing.")]
56    MissingExtraData,
57
58    /// Unsupported schema version
59    #[error("Unsupported schema version: {0}")]
60    UnsupportedSchemaVersion(String),
61}