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)]
15#[non_exhaustive]
16pub enum Error {
17 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
19 Io {
20 context: String,
24 source: std::io::Error,
26 },
27
28 #[error("{msg}", msg = t!("error-io-path", {
30 "path" => path.display().to_string(),
31 "context" => context,
32 "source" => source.to_string(),
33 }))]
34 IoPath {
35 path: PathBuf,
37 context: String,
41 source: std::io::Error,
43 },
44
45 #[error("{msg}", msg = t!("error-io-read", { "context" => context, "source" => source.to_string() }))]
47 IoRead {
48 context: String,
52 source: std::io::Error,
54 },
55
56 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
58 ParseError(String),
59
60 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
62 MissingSection(SectionKeyword),
63
64 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
66 DuplicateSection(SectionKeyword),
67
68 #[error("{msg}", msg = t!("error-invalid-section-for-version", { "section" => section.to_string(), "version" => version.to_string() }))]
70 InvalidSectionForVersion {
71 section: SectionKeyword,
73 version: u8,
75 },
76
77 #[error("{msg}", msg = t!("error-empty-section", { "section" => .0.to_string() }))]
79 EmptySection(SectionKeyword),
80
81 #[error("{msg}", msg = t!("error-no-input-file"))]
83 NoInputFile,
84
85 #[cfg(feature = "cli")]
86 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
88 Json {
89 context: String,
93 source: serde_json::Error,
95 },
96
97 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
99 UnsupportedSchemaVersion(String),
100
101 #[error("{msg}", msg = t!("error-invalid-format"))]
103 InvalidFormat,
104}
105
106impl<'a> From<ParseError<Input<'a>, ParseStack<'a>>> for Error {
107 fn from(value: ParseError<Input<'a>, ParseStack<'a>>) -> Self {
109 Self::ParseError(value.into_inner().to_string())
112 }
113}