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    /// No input file given.
43    ///
44    /// This error only occurs when running the [`crate::commands`] functions.
45    #[error("No input file given.")]
46    NoInputFile,
47
48    /// A parsing error that occurred during winnow file parsing.
49    #[error("File parsing error:\n{0}")]
50    ParseError(String),
51
52    /// JSON error while creating JSON formatted output.
53    ///
54    /// This error only occurs when running the [`crate::commands`] functions.
55    #[error("JSON error: {0}")]
56    Json(#[from] serde_json::Error),
57
58    /// Unsupported schema version
59    #[error("Unsupported schema version: {0}")]
60    UnsupportedSchemaVersion(String),
61
62    /// A alpm-pkgbuild bridge error that occurred when converting a PKGBUILD to a [`SourceInfoV1`]
63    /// struct.
64    ///
65    /// See [`PkgbuildError`] for further details.
66    #[error(transparent)]
67    BridgeError(#[from] PkgbuildError),
68
69    /// A logical error occurred when transforming `alpm-pkgbuild-bridge` script output to a
70    /// [`SourceInfoV1`] struct.
71    ///
72    /// See [`BridgeError`] for further details.
73    #[error(transparent)]
74    BridgeConversionError(#[from] BridgeError),
75}