1use std::path::PathBuf;
4
5use fluent_i18n::t;
6use winnow::error::{ContextError, ParseError};
7
8use crate::desc::SectionKeyword;
9
10#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum Error {
14 #[error("{msg}", msg = t!("error-alpm-types", { "source" => .0.to_string() }))]
16 AlpmTypes(#[from] alpm_types::Error),
17
18 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
20 Io {
21 context: String,
25 source: std::io::Error,
27 },
28
29 #[error("{msg}", msg = t!("error-io-path", {
31 "path" => path.display().to_string(),
32 "context" => context,
33 "source" => source.to_string(),
34 }))]
35 IoPath {
36 path: PathBuf,
38 context: String,
42 source: std::io::Error,
44 },
45
46 #[error("{msg}", msg = t!("error-io-read", { "context" => context, "source" => source.to_string() }))]
48 IoRead {
49 context: String,
53 source: std::io::Error,
55 },
56
57 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
59 Parse(String),
60
61 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
63 MissingSection(SectionKeyword),
64
65 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
67 DuplicateSection(SectionKeyword),
68
69 #[error("{msg}", msg = t!("error-no-input-file"))]
71 NoInputFile,
72
73 #[cfg(feature = "cli")]
74 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
76 Json {
77 context: String,
81 source: serde_json::Error,
83 },
84
85 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
87 UnsupportedSchemaVersion(String),
88
89 #[error("{msg}", msg = t!("error-invalid-format"))]
91 InvalidFormat,
92}
93
94impl<'a> From<ParseError<&'a str, ContextError>> for Error {
95 fn from(value: ParseError<&'a str, ContextError>) -> Self {
97 Self::Parse(value.to_string())
98 }
99}