@@ -32,6 +32,7 @@ use prost::Message;
3232use tempfile:: NamedTempFile ;
3333use thiserror:: Error ;
3434
35+ use crate :: backend:: BackendInitError ;
3536use crate :: backend:: CommitId ;
3637use crate :: backend:: MillisSinceEpoch ;
3738use crate :: backend:: Timestamp ;
@@ -64,6 +65,17 @@ use crate::op_store::WorkspaceId;
6465const OPERATION_ID_LENGTH : usize = 64 ;
6566const VIEW_ID_LENGTH : usize = 64 ;
6667
68+ /// Error that may occur during [`SimpleOpStore`] initialization.
69+ #[ derive( Debug , Error ) ]
70+ #[ error( "Failed to initialize simple operation store" ) ]
71+ pub struct SimpleOpStoreInitError ( #[ from] pub PathError ) ;
72+
73+ impl From < SimpleOpStoreInitError > for BackendInitError {
74+ fn from ( err : SimpleOpStoreInitError ) -> Self {
75+ BackendInitError ( err. into ( ) )
76+ }
77+ }
78+
6779#[ derive( Debug , Error ) ]
6880#[ error( "Failed to read {kind} with ID {id}" ) ]
6981struct DecodeError {
@@ -92,11 +104,14 @@ impl SimpleOpStore {
92104 "simple_op_store"
93105 }
94106
95- /// Creates an empty OpStore, panics if it already exists
96- pub fn init ( store_path : & Path , root_data : RootOperationData ) -> Self {
107+ /// Creates an empty OpStore. Returns error if it already exists.
108+ pub fn init (
109+ store_path : & Path ,
110+ root_data : RootOperationData ,
111+ ) -> Result < Self , SimpleOpStoreInitError > {
97112 let store = Self :: new ( store_path, root_data) ;
98- store. init_base_dirs ( ) . unwrap ( ) ; // TODO: propagate error
99- store
113+ store. init_base_dirs ( ) ? ;
114+ Ok ( store)
100115 }
101116
102117 /// Load an existing OpStore
@@ -794,7 +809,7 @@ mod tests {
794809 let root_data = RootOperationData {
795810 root_commit_id : CommitId :: from_hex ( "000000" ) ,
796811 } ;
797- let store = SimpleOpStore :: init ( temp_dir. path ( ) , root_data) ;
812+ let store = SimpleOpStore :: init ( temp_dir. path ( ) , root_data) . unwrap ( ) ;
798813 let view = create_view ( ) ;
799814 let view_id = store. write_view ( & view) . unwrap ( ) ;
800815 let read_view = store. read_view ( & view_id) . unwrap ( ) ;
@@ -807,7 +822,7 @@ mod tests {
807822 let root_data = RootOperationData {
808823 root_commit_id : CommitId :: from_hex ( "000000" ) ,
809824 } ;
810- let store = SimpleOpStore :: init ( temp_dir. path ( ) , root_data) ;
825+ let store = SimpleOpStore :: init ( temp_dir. path ( ) , root_data) . unwrap ( ) ;
811826 let operation = create_operation ( ) ;
812827 let op_id = store. write_operation ( & operation) . unwrap ( ) ;
813828 let read_operation = store. read_operation ( & op_id) . unwrap ( ) ;
0 commit comments