1use std::path::PathBuf;
4
5use crate::desc::SectionKeyword;
6
7#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum Error {
11 #[error(transparent)]
13 AlpmTypes(#[from] alpm_types::Error),
14
15 #[error("I/O error while {0}:\n{1}")]
17 Io(&'static str, std::io::Error),
18
19 #[error("I/O error at {path} while {context}:\n{source}")]
21 IoPathError {
22 path: PathBuf,
24 context: &'static str,
28 source: std::io::Error,
30 },
31
32 #[error("Read error while {context}:\n{source}")]
34 IoReadError {
35 context: &'static str,
39 source: std::io::Error,
41 },
42
43 #[error("Parser failed with the following error:\n{0}")]
45 ParseError(String),
46
47 #[error("Missing section: %{0}%")]
49 MissingSection(SectionKeyword),
50
51 #[error("Duplicate section: %{0}%")]
53 DuplicateSection(SectionKeyword),
54
55 #[error("No input file given.")]
57 NoInputFile,
58
59 #[cfg(feature = "cli")]
60 #[error("JSON error while {context}:\n{source}")]
62 Json {
63 context: &'static str,
67 source: serde_json::Error,
69 },
70
71 #[error("Unsupported schema version: {0}")]
73 UnsupportedSchemaVersion(String),
74
75 #[error("Failed to parse v1 or v2 format")]
77 InvalidFormat,
78}
79
80impl<'a> From<winnow::error::ParseError<&'a str, winnow::error::ContextError>> for Error {
81 fn from(value: winnow::error::ParseError<&'a str, winnow::error::ContextError>) -> Self {
83 Self::ParseError(value.to_string())
84 }
85}