1
- use crate :: digesters:: { ImmutableFile , ImmutableFileListingError } ;
1
+ use crate :: digesters:: ImmutableFile ;
2
2
use crate :: entities:: ImmutableFileNumber ;
3
- use crate :: StdResult ;
3
+ use crate :: { StdError , StdResult } ;
4
+ use anyhow:: { anyhow, Context } ;
4
5
use async_trait:: async_trait;
5
6
use std:: ops:: Add ;
6
7
use std:: path:: PathBuf ;
14
15
Self : Sync + Send ,
15
16
{
16
17
/// Get the [ImmutableFileNumber] of the last immutable file in the cardano database.
17
- async fn get_last_immutable_number ( & self ) -> Result < u64 , ImmutableFileObserverError > ;
18
+ async fn get_last_immutable_number ( & self ) -> StdResult < u64 > ;
18
19
}
19
20
20
21
/// [ImmutableFileObserver] related errors.
@@ -26,7 +27,7 @@ pub enum ImmutableFileObserverError {
26
27
27
28
/// Raised when [immutable file listing][ImmutableFile::list_completed_in_dir] fails.
28
29
#[ error( "immutable file creation error: {0}" ) ]
29
- ImmutableFileListing ( # [ from ] ImmutableFileListingError ) ,
30
+ ImmutableFileListing ( StdError ) ,
30
31
}
31
32
32
33
/// An [ImmutableFileObserver] using the filesystem.
@@ -45,11 +46,13 @@ impl ImmutableFileSystemObserver {
45
46
46
47
#[ async_trait]
47
48
impl ImmutableFileObserver for ImmutableFileSystemObserver {
48
- async fn get_last_immutable_number ( & self ) -> Result < u64 , ImmutableFileObserverError > {
49
- let immutable_file_number = ImmutableFile :: list_completed_in_dir ( & self . db_path ) ?
49
+ async fn get_last_immutable_number ( & self ) -> StdResult < u64 > {
50
+ let immutable_file_number = ImmutableFile :: list_completed_in_dir ( & self . db_path )
51
+ . map_err ( |e| anyhow ! ( e) )
52
+ . with_context ( || "Immutable File System Observer can not list all immutable files" ) ?
50
53
. into_iter ( )
51
54
. last ( )
52
- . ok_or ( ImmutableFileObserverError :: Missing ( ) ) ?
55
+ . ok_or ( anyhow ! ( ImmutableFileObserverError :: Missing ( ) ) ) ?
53
56
. number ;
54
57
55
58
Ok ( immutable_file_number)
@@ -104,11 +107,11 @@ impl DumbImmutableFileObserver {
104
107
105
108
#[ async_trait]
106
109
impl ImmutableFileObserver for DumbImmutableFileObserver {
107
- async fn get_last_immutable_number ( & self ) -> Result < u64 , ImmutableFileObserverError > {
110
+ async fn get_last_immutable_number ( & self ) -> StdResult < u64 > {
108
111
self . shall_return
109
112
. read ( )
110
113
. await
111
- . ok_or_else ( ImmutableFileObserverError :: Missing )
114
+ . ok_or_else ( || anyhow ! ( ImmutableFileObserverError :: Missing ( ) ) )
112
115
}
113
116
}
114
117
0 commit comments