11//! Error types and Result module.
22
33use displaydoc:: Display ;
4+ use eyre:: Result as EyreResult ;
45use miette:: Diagnostic ;
56use pace_time:: error:: PaceTimeErrorKind ;
67use std:: { error:: Error , io, path:: PathBuf } ;
78use thiserror:: Error ;
89
910use crate :: domain:: activity:: { Activity , ActivityGuid } ;
1011
12+ macro_rules! impl_pace_error_marker {
13+ ( $error: ty) => {
14+ impl PaceErrorMarker for $error { }
15+ } ;
16+ }
17+
1118/// Result type that is being returned from test functions and methods that can fail and thus have errors.
1219pub type TestResult < T > = Result < T , Box < dyn Error + ' static > > ;
1320
@@ -17,6 +24,9 @@ pub type PaceResult<T> = Result<T, PaceError>;
1724/// Result type that is being returned from methods that have optional return values and can fail thus having [`PaceError`]s.
1825pub type PaceOptResult < T > = PaceResult < Option < T > > ;
1926
27+ pub type PaceStorageResult < T > = EyreResult < T > ;
28+ pub type PaceStorageOptResult < T > = EyreResult < Option < T > > ;
29+
2030/// User message type that is being returned from methods that need to print a message to the user.
2131#[ derive( Debug , Clone , PartialEq , Eq ) ]
2232pub struct UserMessage {
@@ -102,9 +112,6 @@ impl PaceError {
102112#[ non_exhaustive]
103113#[ derive( Error , Debug , Display ) ]
104114pub enum PaceErrorKind {
105- // /// [`CommandErrorKind`] describes the errors that can happen while executing a high-level command
106- // #[error(transparent)]
107- // Command(#[from] CommandErrorKind),
108115 /// [`std::io::Error`]
109116 #[ error( transparent) ]
110117 StdIo ( #[ from] std:: io:: Error ) ,
@@ -153,15 +160,16 @@ pub enum PaceErrorKind {
153160 /// Configuration file not found, please run `pace setup config` to initialize `pace`
154161 ParentDirNotFound ( PathBuf ) ,
155162
156- /// Database storage not implemented, yet!
157- DatabaseStorageNotImplemented ,
158-
159163 /// There is no path available to store the activity log
160164 NoPathAvailable ,
161165
162166 /// Templating error: {0}
163167 #[ error( transparent) ]
164168 Template ( #[ from] TemplatingErrorKind ) ,
169+
170+ /// Storage error: {0}
171+ #[ error( transparent) ]
172+ Storage ( #[ from] eyre:: Report ) ,
165173}
166174
167175/// [`ActivityLogErrorKind`] describes the errors that can happen while dealing with the activity log.
@@ -297,20 +305,23 @@ pub enum ActivityStoreErrorKind {
297305
298306 /// Missing category for activity: {0}
299307 MissingCategoryForActivity ( ActivityGuid ) ,
308+
309+ /// Creating ActivityStore from storage failed
310+ CreatingFromStorageFailed ,
300311}
301312
302313trait PaceErrorMarker : Error { }
303314
304- impl PaceErrorMarker for std:: io:: Error { }
305- impl PaceErrorMarker for toml:: de:: Error { }
306- impl PaceErrorMarker for toml:: ser:: Error { }
307- impl PaceErrorMarker for serde_json:: Error { }
308- impl PaceErrorMarker for chrono:: ParseError { }
309- impl PaceErrorMarker for chrono:: OutOfRangeError { }
310- impl PaceErrorMarker for ActivityLogErrorKind { }
311- impl PaceErrorMarker for PaceTimeErrorKind { }
312- impl PaceErrorMarker for ActivityStoreErrorKind { }
313- impl PaceErrorMarker for TemplatingErrorKind { }
315+ impl_pace_error_marker ! ( std:: io:: Error ) ;
316+ impl_pace_error_marker ! ( toml:: de:: Error ) ;
317+ impl_pace_error_marker ! ( toml:: ser:: Error ) ;
318+ impl_pace_error_marker ! ( serde_json:: Error ) ;
319+ impl_pace_error_marker ! ( chrono:: ParseError ) ;
320+ impl_pace_error_marker ! ( chrono:: OutOfRangeError ) ;
321+ impl_pace_error_marker ! ( ActivityLogErrorKind ) ;
322+ impl_pace_error_marker ! ( PaceTimeErrorKind ) ;
323+ impl_pace_error_marker ! ( ActivityStoreErrorKind ) ;
324+ impl_pace_error_marker ! ( TemplatingErrorKind ) ;
314325
315326impl < E > From < E > for PaceError
316327where
0 commit comments