alpm_pkgbuild/
error.rs

1//! All error types that are exposed by this crate.
2
3use std::{path::PathBuf, string::FromUtf8Error};
4
5use fluent_i18n::t;
6use thiserror::Error;
7
8/// The high-level error that can occur when using this crate.
9#[derive(Debug, Error)]
10pub enum Error {
11    /// ALPM types error.
12    #[error(transparent)]
13    AlpmType(#[from] alpm_types::Error),
14
15    /// UTF-8 parse error.
16    #[error(transparent)]
17    InvalidUTF8(#[from] FromUtf8Error),
18
19    /// IO error.
20    #[error("{msg}", msg = t!("error-io", {
21        "context" => context,
22        "source" => source.to_string()
23    }))]
24    Io {
25        /// The context in which the error occurred.
26        ///
27        /// This is meant to complete the sentence "I/O error while ...".
28        context: String,
29        /// The error source.
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        "source" => source.to_string()
38    }))]
39    IoPath {
40        /// The path at which the error occurred.
41        path: PathBuf,
42        /// The context in which the error occurred.
43        ///
44        /// This is meant to complete the sentence "I/O error at path $path while ...".
45        context: String,
46        /// The error source.
47        source: std::io::Error,
48    },
49
50    /// Invalid file encountered.
51    #[error("{msg}", msg = t!("error-invalid-file", {
52        "path" => path,
53        "context" => context
54    }))]
55    InvalidFile {
56        /// The path of the invalid file.
57        path: PathBuf,
58        /// The context in which the error occurred.
59        context: String,
60    },
61
62    /// The alpm-pkgbuild-bridge script could not be found in `$PATH`.
63    #[error("{msg}", msg = t!("error-script-not-found", {
64        "script_name" => script_name,
65        "source" => source.to_string()
66    }))]
67    ScriptNotFound {
68        /// The name of the script that couldn't be found.
69        script_name: String,
70        /// The error source.
71        source: which::Error,
72    },
73
74    /// The pkgbuild bridge script failed to be started.
75    #[error("{msg}", msg = t!("error-script-failed-start", {
76        "context" => context,
77        "parameters" => format!("{parameters:?}"),
78        "source" => source.to_string()
79    }))]
80    ScriptError {
81        /// The context in which the error occurred.
82        context: String,
83        /// The parameters supplied to the script.
84        parameters: Vec<String>,
85        /// The error source.
86        source: std::io::Error,
87    },
88
89    /// The pkgbuild bridge script errored with some log output.
90    #[error("{msg}", msg = t!("error-script-execution", {
91        "parameters" => format!("{parameters:?}"),
92        "stdout" => stdout,
93        "stderr" => stderr
94    }))]
95    ScriptExecutionError {
96        /// The parameters supplied to the script.
97        parameters: Vec<String>,
98        /// The stdout of the failed command.
99        stdout: String,
100        /// The stderr of the failed command.
101        stderr: String,
102    },
103
104    /// A parsing error that occurred during winnow file parsing.
105    #[error("{msg}", msg = t!("error-bridge-parse", { "error" => .0 }))]
106    BridgeParseError(String),
107
108    /// JSON error while creating JSON formatted output.
109    #[error("{msg}", msg = t!("error-json", { "source" => .0.to_string() }))]
110    Json(#[from] serde_json::Error),
111}