1#![deny(missing_docs)]
4
5pub mod action;
7
8pub mod appliers;
10
11pub mod workspace;
13
14pub mod fs_workspace;
16
17pub mod trigger;
19
20pub mod package_class;
22
23pub use debversion::Version;
24pub use trigger::{ChangelogAspect, Trigger, WatchAspect};
25pub use workspace::{Workspace, compat_level};
26
27#[derive(Debug)]
29pub enum Error {
30 NotFound,
32 Io(std::io::Error),
34 Parse(String),
36 Other(String),
38 MissingDependency(String),
40}
41
42impl std::fmt::Display for Error {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 match self {
45 Error::NotFound => write!(f, "file not found"),
46 Error::Io(e) => write!(f, "I/O error: {}", e),
47 Error::Parse(msg) => write!(f, "parse error: {}", msg),
48 Error::Other(msg) => write!(f, "{}", msg),
49 Error::MissingDependency(dep) => write!(f, "missing dependency: {}", dep),
50 }
51 }
52}
53
54impl std::error::Error for Error {
55 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56 match self {
57 Error::Io(e) => Some(e),
58 _ => None,
59 }
60 }
61}
62
63impl From<debian_analyzer::editor::EditorError> for Error {
64 fn from(e: debian_analyzer::editor::EditorError) -> Self {
65 match e {
66 debian_analyzer::editor::EditorError::IoError(e) => Error::Io(e),
67 debian_analyzer::editor::EditorError::BrzError(e) => Error::Other(e.to_string()),
68 debian_analyzer::editor::EditorError::GeneratedFile(p, _) => {
69 Error::Other(format!("generated file: {}", p.display()))
70 }
71 debian_analyzer::editor::EditorError::FormattingUnpreservable(p, _) => {
72 Error::Other(format!("formatting unpreservable: {}", p.display()))
73 }
74 debian_analyzer::editor::EditorError::TemplateError(p, _) => {
75 Error::Other(format!("template error in {}", p.display()))
76 }
77 }
78 }
79}
80
81impl From<std::io::Error> for Error {
82 fn from(e: std::io::Error) -> Self {
83 if e.kind() == std::io::ErrorKind::NotFound {
84 Error::NotFound
85 } else {
86 Error::Io(e)
87 }
88 }
89}