1use std::path::PathBuf;
4
5use fluent_i18n::t;
6
7use crate::desc::SectionKeyword;
8
9#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13 #[error("{msg}", msg = t!("error-alpm-types", { "source" => .0.to_string() }))]
15 AlpmTypes(#[from] alpm_types::Error),
16
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 IoPathError {
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 IoReadError {
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-no-input-file"))]
70 NoInputFile,
71
72 #[cfg(feature = "cli")]
73 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
75 Json {
76 context: String,
80 source: serde_json::Error,
82 },
83
84 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
86 UnsupportedSchemaVersion(String),
87
88 #[error("{msg}", msg = t!("error-invalid-format"))]
90 InvalidFormat,
91}
92
93impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>> for Error {
94 fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
96 Self::ParseError(value.to_string())
97 }
98}