alpm_srcinfo/
error.rs

1//! All error types that are exposed by this crate.
2use std::{path::PathBuf, string::FromUtf8Error};
3
4use alpm_pkgbuild::error::Error as PkgbuildError;
5use fluent_i18n::t;
6use thiserror::Error;
7
8use crate::pkgbuild_bridge::error::BridgeError;
9#[cfg(doc)]
10use crate::{SourceInfoV1, source_info::parser::SourceInfoContent};
11
12/// The high-level error that can occur when using this crate.
13///
14/// Notably, it contains an important enum in the context of parsing:
15/// - `ParseError` is an already formatted error generated by the `winnow` parser. This effectively
16///   means that some invalid data has been encountered
17#[derive(Debug, Error)]
18#[non_exhaustive]
19pub enum Error {
20    /// ALPM type error
21    #[error("{msg}", msg = t!("error-alpm-type", { "error" => .0.to_string() }))]
22    AlpmType(#[from] alpm_types::Error),
23
24    /// IO error
25    #[error("{msg}", msg = t!("error-io", { "context" => .context, "error" => .source.to_string() }))]
26    Io {
27        /// The context in which the IO error occurred.
28        context: String,
29        /// The underlying IO error.
30        source: std::io::Error,
31    },
32
33    /// IO error with additional path info for more context.
34    #[error("{msg}", msg = t!("error-io-path", {
35        "path" => path,
36        "context" => context,
37        "error" => source.to_string()
38    }))]
39    IoPath {
40        /// The path related to the IO error.
41        path: PathBuf,
42        /// The context in which the IO error occurred.
43        context: String,
44        /// The underlying IO error.
45        source: std::io::Error,
46    },
47
48    /// UTF-8 parse error when reading the input file.
49    #[error("{msg}", msg = t!("error-invalid-utf8", { "error" => .0.to_string() }))]
50    InvalidUTF8(#[from] FromUtf8Error),
51
52    /// A section or keyword is missing for a SRCINFO schema version.
53    #[error("{msg}", msg = t!("error-missing-keyword", { "keyword" => keyword }))]
54    MissingKeyword {
55        /// The missing keyword.
56        keyword: &'static str,
57    },
58
59    /// A parsing error that occurred during winnow file parsing.
60    #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
61    ParseError(String),
62
63    /// Unsupported schema version
64    #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
65    UnsupportedSchemaVersion(String),
66
67    /// A alpm-pkgbuild bridge error that occurred when converting a PKGBUILD to a [`SourceInfoV1`].
68    ///
69    /// See [`PkgbuildError`] for further details.
70    #[error("{msg}", msg = t!("error-bridge", { "error" => .0.to_string() }))]
71    BridgeError(#[from] PkgbuildError),
72
73    /// A logical error occurred when transforming `alpm-pkgbuild-bridge` script output to a
74    /// [`SourceInfoV1`] struct.
75    ///
76    /// See [`BridgeError`] for further details.
77    #[error("{msg}", msg = t!("error-bridge-conversion", { "error" => .0.to_string() }))]
78    BridgeConversionError(#[from] BridgeError),
79}