1use std::path::PathBuf;
4
5use fluent_i18n::t;
6
7use crate::desc::SectionKeyword;
8
9#[derive(Debug, thiserror::Error)]
13#[non_exhaustive]
14pub enum Error {
15 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
17 Io {
18 context: String,
22 source: std::io::Error,
24 },
25
26 #[error("{msg}", msg = t!("error-io-path", {
28 "path" => path.display().to_string(),
29 "context" => context,
30 "source" => source.to_string(),
31 }))]
32 IoPathError {
33 path: PathBuf,
35 context: String,
39 source: std::io::Error,
41 },
42
43 #[error("{msg}", msg = t!("error-io-read", { "context" => context, "source" => source.to_string() }))]
45 IoReadError {
46 context: String,
50 source: std::io::Error,
52 },
53
54 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
56 ParseError(String),
57
58 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
60 MissingSection(SectionKeyword),
61
62 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
64 DuplicateSection(SectionKeyword),
65
66 #[error("{msg}", msg = t!("error-invalid-section-for-version", { "section" => section.to_string(), "version" => version.to_string() }))]
68 InvalidSectionForVersion {
69 section: SectionKeyword,
71 version: u8,
73 },
74
75 #[error("{msg}", msg = t!("error-empty-section", { "section" => .0.to_string() }))]
77 EmptySection(SectionKeyword),
78
79 #[error("{msg}", msg = t!("error-no-input-file"))]
81 NoInputFile,
82
83 #[cfg(feature = "cli")]
84 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
86 Json {
87 context: String,
91 source: serde_json::Error,
93 },
94
95 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
97 UnsupportedSchemaVersion(String),
98
99 #[error("{msg}", msg = t!("error-invalid-format"))]
101 InvalidFormat,
102}
103
104impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>> for Error {
105 fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
107 Self::ParseError(value.to_string())
108 }
109}