alpm_pkgbuild/
error.rs

1//! All error types that are exposed by this crate.
2
3use std::{path::PathBuf, string::FromUtf8Error};
4
5use thiserror::Error;
6
7/// The high-level error that can occur when using this crate.
8#[derive(Debug, Error)]
9pub enum Error {
10    /// ALPM types error.
11    #[error(transparent)]
12    AlpmType(#[from] alpm_types::Error),
13
14    /// UTF-8 parse error.
15    #[error(transparent)]
16    InvalidUTF8(#[from] FromUtf8Error),
17
18    /// IO error
19    #[error("I/O error while {context}:\n{source}")]
20    Io {
21        /// The context in which the error occurred.
22        ///
23        /// This is meant to complete the sentence "I/O error while ...".
24        context: &'static str,
25        /// The error source.
26        source: std::io::Error,
27    },
28
29    /// IO error with additional path info for more context.
30    #[error("I/O error at path {path:?} while {context}:\n{source}")]
31    IoPath {
32        /// The path at which the error occurred.
33        path: PathBuf,
34        /// The context in which the error occurred.
35        ///
36        /// This is meant to complete the sentence "I/O error at path $path while ...".
37        context: &'static str,
38        /// The error source
39        source: std::io::Error,
40    },
41
42    /// Invalid file encountered
43    #[error("Encountered invalid file for path {path:?}:\n{context}")]
44    InvalidFile {
45        /// The path of the file that's invalid
46        path: PathBuf,
47        /// The context in which the error occurred.
48        ///
49        /// This is meant to complete the sentence "Encountered invalid file for path ...".
50        context: &'static str,
51    },
52
53    /// The alpm-pkgbuild-bridge script could not be found in `$PATH`.
54    #[error("Could not find '{script_name}' script in $PATH:\n{source}")]
55    ScriptNotFound {
56        /// The name of the script that couldn't be found.
57        script_name: String,
58        /// The error source
59        source: which::Error,
60    },
61
62    /// The pkgbuild bridge script failed to be started.
63    #[error(
64        "Failed to {context} process to extract PKGBUILD:\nCommand: alpm-pkgbuild-bridge {parameters:?}\n{source}"
65    )]
66    ScriptError {
67        /// The context in which the error occurred.
68        ///
69        /// This is meant to complete the sentence "Failed to ...".
70        context: &'static str,
71        /// The parameters that were supplied to the script.
72        parameters: Vec<String>,
73        /// The error source
74        source: std::io::Error,
75    },
76
77    /// The pkgbuild bridge script errored with some log output.
78    #[error(
79        "Error during pkgbuild bridge execution:\nCommand: alpm-pkgbuild-bridge {parameters:?}\nstdout:{stdout}\n\nstderr:{stderr}"
80    )]
81    ScriptExecutionError {
82        /// The parameters that were supplied to the script.
83        parameters: Vec<String>,
84        /// The stdout of the failed command.
85        stdout: String,
86        /// The stderr of the failed command.
87        stderr: String,
88    },
89
90    /// A parsing error that occurred during winnow file parsing.
91    #[error(
92        "An unexpected error occurred in the output parser for the 'alpm-pkgbuild-bridge' script:\n{0}\n\nPlease report this as a bug at https://gitlab.archlinux.org/archlinux/alpm/alpm/-/issues"
93    )]
94    BridgeParseError(String),
95
96    /// JSON error while creating JSON formatted output.
97    ///
98    /// This error only occurs when running the `commands` functions.
99    #[error("JSON error: {0}")]
100    Json(#[from] serde_json::Error),
101}