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)]
13#[non_exhaustive]
14pub enum Error {
15 #[error("{msg}", msg = t!("error-alpm-types", { "source" => .0.to_string() }))]
17 AlpmTypes(#[from] alpm_types::Error),
18
19 #[error("{msg}", msg = t!("error-alpm-mtree", { "source" => .0.to_string() }))]
21 AlpmMtree(#[from] alpm_mtree::Error),
22
23 #[error("{msg}", msg = t!("error-database", { "source" => .0.to_string() }))]
25 Database(#[from] crate::db::Error),
26
27 #[error("{msg}", msg = t!("error-db-files", { "source" => .0.to_string() }))]
31 DbFiles(#[from] crate::files::Error),
32
33 #[error("{msg}", msg = t!("error-io", { "context" => context, "source" => source.to_string() }))]
35 Io {
36 context: String,
40 source: std::io::Error,
42 },
43
44 #[error("{msg}", msg = t!("error-io-path", {
46 "path" => path.display().to_string(),
47 "context" => context,
48 "source" => source.to_string(),
49 }))]
50 IoPath {
51 path: PathBuf,
53 context: String,
57 source: std::io::Error,
59 },
60
61 #[error("{msg}", msg = t!("error-parse", { "error" => .0 }))]
63 Parse(String),
64
65 #[error("{msg}", msg = t!("error-missing-section", { "section" => .0.to_string() }))]
67 MissingSection(SectionKeyword),
68
69 #[error("{msg}", msg = t!("error-duplicate-section", { "section" => .0.to_string() }))]
71 DuplicateSection(SectionKeyword),
72
73 #[error("{msg}", msg = t!("error-no-input-file"))]
75 NoInputFile,
76
77 #[error("{msg}", msg = t!("error-json", { "context" => context, "source" => source.to_string() }))]
79 Json {
80 context: String,
84 source: serde_json::Error,
86 },
87
88 #[error("{msg}", msg = t!("error-unsupported-schema-version", { "version" => .0 }))]
90 UnsupportedSchemaVersion(String),
91}
92
93impl<'a> From<ParseError<Input<'a>, ParseStack<'a>>> for Error {
94 fn from(value: ParseError<Input<'a>, ParseStack<'a>>) -> Self {
96 Self::Parse(value.into_inner().to_string())
99 }
100}