1use std::{path::PathBuf, string::FromUtf8Error};
3
4use alpm_parsers::error::{Input, ParseStack};
5use alpm_pkgbuild::error::Error as PkgbuildError;
6use fluent_i18n::t;
7use thiserror::Error;
8use winnow::error::ParseError;
9
10use crate::pkgbuild_bridge::error::BridgeError;
11#[cfg(doc)]
12use crate::{SourceInfoV1, source_info::parser::SourceInfoContent};
13
14#[derive(Debug, Error)]
20#[non_exhaustive]
21pub enum Error {
22 #[error("{msg}", msg = t!("error-alpm-type", { "error" => .0.to_string() }))]
24 AlpmType(#[from] alpm_types::Error),
25
26 #[error("{msg}", msg = t!("error-io", { "context" => .context, "error" => .source.to_string() }))]
28 Io {
29 context: String,
31 source: std::io::Error,
33 },
34
35 #[error("{msg}", msg = t!("error-io-path", {
37 "path" => path,
38 "context" => context,
39 "error" => source.to_string()
40 }))]
41 IoPath {
42 path: PathBuf,
44 context: String,
46 source: std::io::Error,
48 },
49
50 #[error("{msg}", msg = t!("error-invalid-utf8", { "error" => .0.to_string() }))]
52 InvalidUTF8(#[from] FromUtf8Error),
53
54 #[error("{msg}", msg = t!("error-missing-keyword", { "keyword" => keyword }))]
56 MissingKeyword {
57 keyword: &'static str,
59 },
60
61 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
63 ParseError(String),
64
65 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
67 UnsupportedSchemaVersion(String),
68
69 #[error("{msg}", msg = t!("error-bridge", { "error" => .0.to_string() }))]
74 BridgeError(#[from] PkgbuildError),
75
76 #[error("{msg}", msg = t!("error-bridge-conversion", { "error" => .0.to_string() }))]
81 BridgeConversionError(#[from] BridgeError),
82}
83
84impl<'a> From<ParseError<Input<'a>, ParseStack<'a>>> for Error {
85 fn from(value: ParseError<Input<'a>, ParseStack<'a>>) -> Self {
87 Self::ParseError(value.into_inner().to_string())
90 }
91}