asimov_registry/registry/
error.rs1use std::{io, path::PathBuf, string::String};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum CreateFileTreeError {
8 #[error("failed to create directory for installed modules `{0}`: {1}")]
9 InstallDir(PathBuf, #[source] io::Error),
10 #[error("failed to create directory for enabled modules `{0}`: {1}")]
11 EnableDir(PathBuf, #[source] io::Error),
12 #[error("failed to create directory for module binaries `{0}`: {1}")]
13 ExecDir(PathBuf, #[source] io::Error),
14}
15
16#[derive(Debug, Error)]
17pub enum AddModuleError {
18 #[error("module is already installed")]
19 AlreadyInstalled,
20 #[error("failed to install module from `{0}` to `{1}`: {2}")]
21 Install(PathBuf, PathBuf, #[source] io::Error),
22 #[error("failed to read directory of module binaries `{0}`: {1}")]
23 ReadBinDir(PathBuf, #[source] io::Error),
24 #[error("failed to add module binary `{0}`: {1}")]
25 AddBinary(String, #[source] io::Error),
26}
27
28#[derive(Debug, Error)]
29pub enum ReadReadmeError {
30 #[error("module is not installed")]
31 NotInstalled,
32 #[error("error while checking whether module is installed: {0}")]
33 IsModuleInstalled(#[from] IsModuleInstalledError),
34 #[error("failed to read module README at `{0}`: {1}")]
35 Read(PathBuf, #[source] io::Error),
36}
37
38#[derive(Debug, Error)]
39pub enum ManifestError {
40 #[error("module is not installed")]
41 NotInstalled,
42 #[error("error while searching for manifest file: {0}")]
43 FindManifest(#[from] FindManifestError),
44 #[error("unable to read module manifest: {0}")]
45 Read(#[from] ReadManifestError),
46}
47
48#[derive(Debug, Error)]
49#[error(transparent)]
50pub struct ModuleVersionError(#[from] ManifestError);
51
52#[derive(Debug, Error)]
53pub enum RemoveModuleError {
54 #[error("error while searching for manifest file: {0}")]
55 FindManifest(#[from] FindManifestError),
56 #[error("module is not installed")]
57 NotInstalled,
58 #[error("failed to remove directory of installed module `{0}`: {1}")]
59 RemoveModuleDir(PathBuf, #[source] io::Error),
60}
61
62#[derive(Debug, Error)]
63pub enum RemoveBinaryError {
64 #[error("invalid program name `{0}`")]
65 InvalidName(String),
66 #[error("failed to remove binary: {0}")]
67 Io(#[from] io::Error),
68}
69
70#[derive(Debug, Error)]
71pub enum InstalledModulesError {
72 #[error("failed to read directory for installed modules `{0}`: {1}")]
73 DirIo(PathBuf, #[source] io::Error),
74 #[error("failed to read manifest at `{0}`: {1}")]
75 ReadManifestError(PathBuf, #[source] ReadManifestError),
76}
77
78#[derive(Debug, Error)]
79pub enum EnabledModulesError {
80 #[error("failed to read directory for enabled modules `{0}`: {1}")]
81 DirIo(PathBuf, #[source] io::Error),
82 #[error("failed to read manifest at `{0}`: {1}")]
83 ReadManifestError(PathBuf, #[source] ReadManifestError),
84}
85
86#[derive(Debug, Error)]
87#[error("error while searching for manifest file: {0}")]
88pub struct IsModuleInstalledError(#[from] FindManifestError);
89
90#[derive(Debug, Error)]
91#[error("unable to read symlink for enabled module: {0}")]
92pub struct IsModuleEnabledError(#[from] io::Error);
93
94#[derive(Debug, Error)]
95pub enum EnableError {
96 #[error("module is not installed")]
97 NotInstalled,
98 #[error("failed to enable module: {0}")]
99 Io(#[from] io::Error),
100}
101
102#[derive(Debug, Error)]
103#[error("failed to disable module: {0}")]
104pub struct DisableError(#[from] pub io::Error);
105
106mod common {
107 use super::*;
108
109 #[derive(Debug, Error)]
110 pub enum ReadManifestError {
111 #[error("failed to access module manifest file: {0}")]
112 InstalledManifestIo(#[from] io::Error),
113 #[error("failed to deserialize module manifest: {0}")]
114 ManifestDeserialize(#[from] DeserializeError),
115 }
116
117 impl From<serde_json::Error> for ReadManifestError {
118 fn from(value: serde_json::Error) -> Self {
119 ReadManifestError::ManifestDeserialize(DeserializeError::Json(value))
120 }
121 }
122
123 impl From<serde_yaml_ng::Error> for ReadManifestError {
124 fn from(value: serde_yaml_ng::Error) -> Self {
125 ReadManifestError::ManifestDeserialize(DeserializeError::Yaml(value))
126 }
127 }
128
129 #[derive(Debug, Error)]
130 pub enum DeserializeError {
131 #[error("JSON deserialization failed: {0}")]
132 Json(#[from] serde_json::Error),
133 #[error("YAML deserialization failed: {0}")]
134 Yaml(#[from] serde_yaml_ng::Error),
135 }
136
137 #[derive(Debug, Error)]
138 #[error("unable to check for manifest file at `{0}`: {1}")]
139 pub struct FindManifestError(pub PathBuf, #[source] pub io::Error);
140
141 #[derive(Debug, Error)]
142 pub enum SerializeError {
143 #[error("JSON serialization failed: {0}")]
144 Json(#[from] serde_json::Error),
145 #[error("YAML serialization failed: {0}")]
146 Yaml(#[from] serde_yaml_ng::Error),
147 }
148}
149pub use common::*;