File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed
Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 11use super :: otp_element:: OTPDatabase ;
22struct Migration < ' a > {
33 to_version : u16 , // Database version which we are migrating on
4- migration_function : & ' a dyn Fn ( & mut OTPDatabase ) , // Function to execute the migration
4+ migration_function : & ' a dyn Fn ( & mut OTPDatabase ) -> color_eyre :: Result < ( ) > , // Function to execute the migration
55}
66const MIGRATIONS_LIST : [ Migration ; 1 ] = [ Migration {
77 to_version : 2 ,
88 migration_function : & migrate_to_2,
99} ] ;
1010
11- fn migrate_to_2 ( database : & mut OTPDatabase ) {
11+ fn migrate_to_2 ( database : & mut OTPDatabase ) -> color_eyre :: Result < ( ) > {
1212 database. version = 2 ;
13+ Ok ( ( ) )
1314}
1415
15- pub fn migrate ( database : & mut OTPDatabase ) {
16+ pub fn migrate ( database : & mut OTPDatabase ) -> color_eyre :: Result < ( ) > {
1617 let mut binding = MIGRATIONS_LIST ;
1718 let migrations = binding. as_mut ( ) ;
1819 migrations. sort_unstable_by ( |c1, c2| c1. to_version . cmp ( & c2. to_version ) ) ;
1920 for i in migrations {
2021 if database. version < i. to_version {
2122 // Do the migration
22- ( i. migration_function ) ( database) ;
23+ ( i. migration_function ) ( database) ? ;
2324 }
2425 }
26+ Ok ( ( ) )
2527}
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ impl OTPDatabase {
5959
6060 pub fn save ( & mut self , key : & Vec < u8 > , salt : & [ u8 ] ) -> color_eyre:: Result < ( ) > {
6161 self . needs_modification = false ;
62- migrate ( self ) ;
62+ migrate ( self ) ? ;
6363 match self . overwrite_database_key ( key, salt) {
6464 Ok ( ( ) ) => Ok ( ( ) ) ,
6565 Err ( e) => Err ( ErrReport :: from ( e) ) ,
You can’t perform that action at this time.
0 commit comments