@@ -22,13 +22,29 @@ use std::io;
2222use std:: path:: Path ;
2323use std:: path:: PathBuf ;
2424
25+ use thiserror:: Error ;
26+
27+ use crate :: backend:: BackendInitError ;
28+ use crate :: file_util:: IoResultExt as _;
29+ use crate :: file_util:: PathError ;
2530use crate :: lock:: FileLock ;
2631use crate :: object_id:: ObjectId ;
2732use crate :: op_heads_store:: OpHeadsStore ;
2833use crate :: op_heads_store:: OpHeadsStoreError ;
2934use crate :: op_heads_store:: OpHeadsStoreLock ;
3035use crate :: op_store:: OperationId ;
3136
37+ /// Error that may occur during [`SimpleOpHeadsStore`] initialization.
38+ #[ derive( Debug , Error ) ]
39+ #[ error( "Failed to initialize simple operation heads store" ) ]
40+ pub struct SimpleOpHeadsStoreInitError ( #[ from] pub PathError ) ;
41+
42+ impl From < SimpleOpHeadsStoreInitError > for BackendInitError {
43+ fn from ( err : SimpleOpHeadsStoreInitError ) -> Self {
44+ BackendInitError ( err. into ( ) )
45+ }
46+ }
47+
3248pub struct SimpleOpHeadsStore {
3349 dir : PathBuf ,
3450}
@@ -46,10 +62,10 @@ impl SimpleOpHeadsStore {
4662 "simple_op_heads_store"
4763 }
4864
49- pub fn init ( dir : & Path ) -> Self {
65+ pub fn init ( dir : & Path ) -> Result < Self , SimpleOpHeadsStoreInitError > {
5066 let op_heads_dir = dir. join ( "heads" ) ;
51- fs:: create_dir ( & op_heads_dir) . unwrap ( ) ;
52- Self { dir : op_heads_dir }
67+ fs:: create_dir ( & op_heads_dir) . context ( & op_heads_dir ) ? ;
68+ Ok ( Self { dir : op_heads_dir } )
5369 }
5470
5571 pub fn load ( dir : & Path ) -> Self {
0 commit comments