1use std::path::PathBuf;
4
5use alpm_parsers::error::{Input, ParseStack};
6use fluent_i18n::t;
7use winnow::error::ParseError;
8
9use crate::desc::SectionKeyword;
10
11#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum Error {
15 #[error("{msg}", msg = t!("error-alpm-types", { "source" => .0.to_string() }))]
17 AlpmTypes(#[from] alpm_types::Error),
18
19 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
21 Io {
22 context: String,
26 source: std::io::Error,
28 },
29
30 #[error("{msg}", msg = t!("error-io-path", {
32 "path" => path.display().to_string(),
33 "context" => context,
34 "source" => source.to_string(),
35 }))]
36 IoPath {
37 path: PathBuf,
39 context: String,
43 source: std::io::Error,
45 },
46
47 #[error("{msg}", msg = t!("error-io-read", { "context" => context, "source" => source.to_string() }))]
49 IoRead {
50 context: String,
54 source: std::io::Error,
56 },
57
58 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
60 Parse(String),
61
62 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
64 MissingSection(SectionKeyword),
65
66 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
68 DuplicateSection(SectionKeyword),
69
70 #[error("{msg}", msg = t!("error-no-input-file"))]
72 NoInputFile,
73
74 #[cfg(feature = "cli")]
75 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
77 Json {
78 context: String,
82 source: serde_json::Error,
84 },
85
86 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
88 UnsupportedSchemaVersion(String),
89
90 #[error("{msg}", msg = t!("error-invalid-format"))]
92 InvalidFormat,
93}
94
95impl<'a> From<ParseError<Input<'a>, ParseStack<'a>>> for Error {
96 fn from(value: ParseError<Input<'a>, ParseStack<'a>>) -> Self {
98 Self::Parse(value.into_inner().to_string())
101 }
102}