alpm_pkginfo/
error.rs

1use std::{path::PathBuf, string::FromUtf8Error};
2
3use fluent_i18n::t;
4
5/// The Error that can occur when working with PKGINFO files.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9    /// ALPM type error
10    #[error(transparent)]
11    AlpmType(#[from] alpm_types::Error),
12
13    /// IO path error
14    #[error("{msg}", msg = t!("error-io-path", {
15        "path" => path,
16        "context" => context,
17        "source" => source.to_string()
18    }))]
19    IoPathError {
20        /// The path where the error occurred.
21        ///
22        /// This is meant to complete the sentence "I/O error while  ".
23        path: PathBuf,
24        /// The context in which the error occurred.
25        context: String,
26        /// The error source.
27        source: std::io::Error,
28    },
29
30    /// I/O error while reading a buffer.
31    #[error("{msg}", msg = t!("error-io-read", {
32        "context" => context,
33        "source" => source.to_string()
34    }))]
35    IoReadError {
36        /// The context in which the error occurred.
37        ///
38        /// This is meant to complete the sentence "Read error while ".
39        context: String,
40        /// The error source.
41        source: std::io::Error,
42    },
43
44    /// UTF-8 parse error.
45    #[error(transparent)]
46    InvalidUTF8(#[from] FromUtf8Error),
47
48    /// An [`alpm_parsers::custom_ini::Error`].
49    #[error("{msg}", msg = t!("error-deserialize", { "source" => source.to_string() }))]
50    DeserializeError {
51        /// The deserialization error source.
52        #[from]
53        source: alpm_parsers::custom_ini::Error,
54    },
55
56    /// An extra data field specified without any value.
57    #[error("{msg}", msg = t!("error-extra-data-empty"))]
58    ExtraDataEmpty,
59
60    /// The first extra data field does not specify "pkgtype".
61    #[error("{msg}", msg = t!("error-first-extra-data-not-pkgtype"))]
62    FirstExtraDataNotPkgType,
63
64    /// An invalid enum variant
65    #[error("{msg}", msg = t!("error-invalid-variant", { "error" => 0.to_string() }))]
66    InvalidVariant(#[from] strum::ParseError),
67
68    /// Unsupported schema version.
69    #[error("{msg}", msg = t!("error-unsupported-schema", { "version" => .0 }))]
70    UnsupportedSchemaVersion(String),
71}