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)]
14#[non_exhaustive]
15pub enum Error {
16 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
18 Io {
19 context: String,
23 source: std::io::Error,
25 },
26
27 #[error("{msg}", msg = t!("error-io-path", {
29 "path" => path.display().to_string(),
30 "context" => context,
31 "source" => source.to_string(),
32 }))]
33 IoPath {
34 path: PathBuf,
36 context: String,
40 source: std::io::Error,
42 },
43
44 #[error("{msg}", msg = t!("error-io-read", { "context" => context, "source" => source.to_string() }))]
46 IoRead {
47 context: String,
51 source: std::io::Error,
53 },
54
55 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
57 ParseError(String),
58
59 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
61 MissingSection(SectionKeyword),
62
63 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
65 DuplicateSection(SectionKeyword),
66
67 #[error("{msg}", msg = t!("error-invalid-section-for-version", { "section" => section.to_string(), "version" => version.to_string() }))]
69 InvalidSectionForVersion {
70 section: SectionKeyword,
72 version: u8,
74 },
75
76 #[error("{msg}", msg = t!("error-empty-section", { "section" => .0.to_string() }))]
78 EmptySection(SectionKeyword),
79
80 #[error("{msg}", msg = t!("error-no-input-file"))]
82 NoInputFile,
83
84 #[cfg(feature = "cli")]
85 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
87 Json {
88 context: String,
92 source: serde_json::Error,
94 },
95
96 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
98 UnsupportedSchemaVersion(String),
99
100 #[error("{msg}", msg = t!("error-invalid-format"))]
102 InvalidFormat,
103}
104
105impl<'a> From<ParseError<&'a str, ContextError>> for Error {
106 fn from(value: ParseError<&'a str, ContextError>) -> Self {
108 Self::ParseError(value.to_string())
109 }
110}