alpm_buildinfo/
error.rs

1use std::{path::PathBuf, string::FromUtf8Error};
2
3use alpm_types::SchemaVersion;
4use fluent_i18n::t;
5
6/// The Error that can occur when working with BUILDINFO files.
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// ALPM type error.
11    #[error("{msg}", msg = t!("error-alpm-type", { "source" => .0.to_string() }))]
12    AlpmType(#[from] alpm_types::Error),
13
14    /// IO error.
15    #[error("{msg}", msg = t!("error-io-path", {
16        "path" => path.display().to_string(),
17        "context" => context,
18        "source" => source.to_string()
19    }))]
20    IoPathError {
21        /// The path where the error occurred.
22        path: PathBuf,
23        /// The context in which the error occurred.
24        ///
25        /// This is meant to complete the sentence "I/O error at path ".
26        context: String,
27        /// The error source.
28        source: std::io::Error,
29    },
30
31    /// I/O error while reading a buffer.
32    #[error("{msg}", msg = t!("error-io-read", {
33        "context" => context,
34        "source" => source.to_string()
35    }))]
36    IoReadError {
37        /// The context in which the error occurred.
38        ///
39        /// This is meant to complete the sentence "Read error while ".
40        context: String,
41        /// The error source.
42        source: std::io::Error,
43    },
44
45    /// UTF-8 parse error.
46    #[error(transparent)]
47    InvalidUTF8(#[from] FromUtf8Error),
48
49    /// An [`alpm_parsers::custom_ini::Error`].
50    #[error("{msg}", msg = t!("error-deserialize-buildinfo", { "source" => .0.to_string() }))]
51    DeserializeError(#[from] alpm_parsers::custom_ini::Error),
52
53    /// Unsupported schema version
54    #[error("Unsupported schema version: {0}")]
55    UnsupportedSchemaVersion(String),
56
57    /// A SchemaVersion with the wrong version is used.
58    #[error("{msg}", msg = t!("error-wrong-schema-version", { "version" => .0.to_string() }))]
59    WrongSchemaVersion(SchemaVersion),
60
61    /// BuildInfo file is missing the format field.
62    #[error("{msg}", msg = t!("error-missing-format-field"))]
63    MissingFormatField,
64}