1use std::io;
2use std::path::PathBuf;
3
4use thiserror::Error;
5
6use crate::config::ConfigError;
7
8#[derive(Debug, Error)]
9pub enum RunnerError {
10 #[error("No configuration file found in the current directory.")]
11 ConfigNotFound,
12
13 #[error(transparent)]
14 ConfigReadError(#[from] ConfigError),
15
16 #[error("'.pkgs' directory already exists but is not a directory.")]
17 PkgsDirNotADir,
18
19 #[error("Package directory '.pkgs' not found.")]
20 PkgsDirNotFound,
21
22 #[error(transparent)]
23 Io(#[from] IoError),
24
25 #[error("Fail to load {module}: {source}")]
26 LoadModuleError { source: LoadError, module: String },
27
28 #[error("Fail to unload {module}: {source}")]
29 UnloadModuleError { source: UnloadError, module: String },
30
31 #[error("No action to rollback")]
32 NoActionToRollback,
33}
34
35#[derive(Debug, Error)]
36#[error("Io error while {action}: {source}")]
37pub struct IoError {
38 pub source: io::Error,
39 pub action: String,
40}
41
42#[derive(Debug, Error)]
43pub enum LoadError {
44 #[error(transparent)]
45 Io(#[from] IoError),
46
47 #[error("package directory for '{0}' not found")]
48 PkgDirNotFound(String),
49
50 #[error("source '{0}' does not exist")]
51 SrcNotExists(String),
52
53 #[error("'{dst}' for '{src}' already exists")]
54 DstAlreadyExists { src: String, dst: PathBuf },
55
56 #[error("'{dst}' for '{src}' found in trace file but not a symlink")]
57 DstNotSymlink { src: String, dst: PathBuf },
58}
59
60#[derive(Debug, Error)]
61pub enum UnloadError {
62 #[error(transparent)]
63 Io(#[from] IoError),
64
65 #[error("'{dst}' for '{src}' does not exist")]
66 DstNotFound { src: String, dst: PathBuf },
67
68 #[error("'{dst}' for '{src}' found in trace file but not a symlink")]
69 DstNotSymlink { src: String, dst: PathBuf },
70}
71
72impl RunnerError {
73 pub fn unwrap_load(self) -> LoadError {
74 match self {
75 RunnerError::LoadModuleError { source, .. } => source,
76 _ => panic!("Called unwrap_load on a non-LoadModuleError variant"),
77 }
78 }
79
80 pub fn unwrap_unload(self) -> UnloadError {
81 match self {
82 RunnerError::UnloadModuleError { source, .. } => source,
83 _ => panic!("Called unwrap_unload on a non-UnloadModuleError variant"),
84 }
85 }
86}