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 thiserror::Error;
6
7use crate::pkgbuild_bridge::error::BridgeError;
8#[cfg(doc)]
9use crate::{SourceInfoV1, source_info::parser::SourceInfoContent};
10
11/// The high-level error that can occur when using this crate.
12///
13/// Notably, it contains an important enum in the context of parsing:
14/// - `ParseError` is an already formatted error generated by the `winnow` parser. This effectively
15///   means that some invalid data has been encountered
16#[derive(Debug, Error)]
17#[non_exhaustive]
18pub enum Error {
19    /// ALPM type error
20    #[error("ALPM type parse error: {0}")]
21    AlpmType(#[from] alpm_types::Error),
22
23    /// IO error
24    #[error("I/O error while {0}:\n{1}")]
25    Io(&'static str, std::io::Error),
26
27    /// IO error with additional path info for more context.
28    #[error("I/O error at path {0:?} while {1}:\n{2}")]
29    IoPath(PathBuf, &'static str, std::io::Error),
30
31    /// UTF-8 parse error when reading the input file.
32    #[error(transparent)]
33    InvalidUTF8(#[from] FromUtf8Error),
34
35    /// A section or keyword is missing for a SRCINFO schema version.
36    #[error("The SRCINFO data misses the required keyword '{keyword}'")]
37    MissingKeyword {
38        /// The missing keyword.
39        keyword: &'static str,
40    },
41
42    /// A parsing error that occurred during winnow file parsing.
43    #[error("File parsing error:\n{0}")]
44    ParseError(String),
45
46    /// Unsupported schema version
47    #[error("Unsupported schema version: {0}")]
48    UnsupportedSchemaVersion(String),
49
50    /// A alpm-pkgbuild bridge error that occurred when converting a PKGBUILD to a [`SourceInfoV1`]
51    /// struct.
52    ///
53    /// See [`PkgbuildError`] for further details.
54    #[error(transparent)]
55    BridgeError(#[from] PkgbuildError),
56
57    /// A logical error occurred when transforming `alpm-pkgbuild-bridge` script output to a
58    /// [`SourceInfoV1`] struct.
59    ///
60    /// See [`BridgeError`] for further details.
61    #[error(transparent)]
62    BridgeConversionError(#[from] BridgeError),
63}