1use super::*;
5use coven_foundation::files::BootstrapDirectoryError;
6
7#[derive(Debug, thiserror::Error)]
12pub enum BootstrapError {
13 #[error("opening cancelled")]
15 Cancelled,
16 #[error("the join request may have been sent; the join stays unfinished")]
20 JoinRequestSent,
21 #[error("no join is under way for store {0}")]
24 NoUnfinishedJoin(StoreId),
25 #[error("no unfinished installation of store {0} to discard")]
28 NoUnfinishedInstallation(StoreId),
29 #[error("the device may be registered; the restore stays unfinished")]
32 RestoreRegistered,
33 #[error("no restore is under way for store {0}")]
36 NoUnfinishedRestore(StoreId),
37 #[error("no replacement is under way for store {0}")]
41 NoUnfinishedReplacement(StoreId),
42 #[error("the invite was shared with {invited}, but the sign-in is {signed_in}")]
47 WrongAccount {
48 invited: String,
51 signed_in: String,
53 },
54 #[error(transparent)]
56 Code(#[from] CodeError),
57 #[error(transparent)]
59 Directory(BootstrapDirectoryError),
60 #[error(transparent)]
62 Store(CovenError),
63 #[error("{}: the device is locked, and the store's files are protected until it unlocks", path.display())]
69 DeviceLocked {
70 path: std::path::PathBuf,
72 },
73 #[error(transparent)]
75 Sync(SyncError),
76 #[error(transparent)]
78 OAuth(coven_storage::providers::OAuthError),
79 #[error(transparent)]
81 SecureStorage(KeyError),
82 #[error("{operation}; cleanup failed: {cleanup}")]
84 Cleanup {
85 operation: Box<BootstrapError>,
87 #[source]
89 cleanup: Box<BootstrapError>,
90 },
91 #[error("store is published; final durability or cleanup failed: {source}")]
94 Published {
95 handle: CovenHandle,
97 #[source]
99 source: Box<BootstrapError>,
100 },
101 #[error(transparent)]
104 Shutdown(#[from] crate::task::Shutdown),
105 #[error(transparent)]
107 Bug(#[from] crate::task::Bug),
108}
109
110impl From<BootstrapDirectoryError> for BootstrapError {
111 fn from(error: BootstrapDirectoryError) -> Self {
112 if let BootstrapDirectoryError::Bug(bug) = error {
113 return Self::Bug(bug);
114 }
115 match error.device_locked() {
116 Some(path) => Self::DeviceLocked { path: path.to_owned() },
117 None => Self::Directory(error),
118 }
119 }
120}
121
122impl From<SyncError> for BootstrapError {
125 fn from(error: SyncError) -> Self {
126 match error {
127 SyncError::Code(error) => Self::Code(error),
128 SyncError::Bug(bug) => Self::Bug(bug),
129 error => Self::Sync(error),
130 }
131 }
132}
133
134impl From<CovenError> for BootstrapError {
135 fn from(error: CovenError) -> Self {
136 match error {
137 CovenError::DeviceLocked { path } => Self::DeviceLocked { path },
138 CovenError::Bug(bug) => Self::Bug(bug),
139 error => Self::Store(error),
140 }
141 }
142}
143
144impl From<DbError> for BootstrapError {
146 fn from(error: DbError) -> Self {
147 CovenError::from(error).into()
148 }
149}
150
151impl From<coven_database::OpenError> for BootstrapError {
152 fn from(error: coven_database::OpenError) -> Self {
153 CovenError::from(error).into()
154 }
155}
156
157impl From<coven_storage::providers::OAuthError> for BootstrapError {
158 fn from(error: coven_storage::providers::OAuthError) -> Self {
159 match error {
160 coven_storage::providers::OAuthError::Storage(StorageError::Bug(bug)) => Self::Bug(bug),
161 error => Self::OAuth(error),
162 }
163 }
164}
165
166impl From<StoreLockError> for BootstrapError {
167 fn from(error: StoreLockError) -> Self {
168 BootstrapDirectoryError::from(error).into()
169 }
170}
171
172impl From<coven_foundation::files::FileError> for BootstrapError {
173 fn from(error: coven_foundation::files::FileError) -> Self {
174 BootstrapDirectoryError::from(error).into()
175 }
176}
177
178impl From<KeyError> for BootstrapError {
179 fn from(error: KeyError) -> Self {
180 match error {
181 KeyError::Bug(bug) => Self::Bug(bug),
182 error => Self::SecureStorage(error),
183 }
184 }
185}
186
187impl crate::task::CarriesBug for BootstrapError {
188 fn bug(&self) -> Option<&crate::task::Bug> {
189 match self {
190 Self::Bug(bug) => Some(bug),
191 Self::Directory(error) => error.bug(),
192 Self::Store(error) => error.bug(),
193 Self::Sync(error) => error.bug(),
194 Self::OAuth(error) => error.bug(),
195 Self::SecureStorage(error) => error.bug(),
196 Self::Cleanup { operation, cleanup } => operation.bug().or_else(|| cleanup.bug()),
197 Self::Published { source, .. } => source.bug(),
198 _ => None,
199 }
200 }
201}
202
203impl From<crate::task::TaskFailed> for BootstrapError {
204 fn from(failed: crate::task::TaskFailed) -> Self {
205 failed.into_error()
206 }
207}