diff --git a/src/main.rs b/src/main.rs index 544fb94..537f1ec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use { libadwaita :: { * , prelude :: * } , } ; -use crate :: { error :: * , persistence :: * , ui :: * } ; +use crate :: { error :: { * , ZoodexError :: * } , persistence :: * , ui :: * } ; @@ -33,6 +33,9 @@ fn on_activate ( app : & Application ) { Ok (()) } , |_| () , |error| { + match error { + CollectionFileError => eprintln ! ("Could not open collection file") , + } ; ui . close_window () ; } ) . await ; } ) ; diff --git a/src/persistence.rs b/src/persistence.rs index 759c980..6858d43 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -1,4 +1,8 @@ -use { fallible_iterator :: * , rusqlite :: { Connection , Error :: * } } ; +use { + fallible_iterator :: * , + rusqlite :: { Connection , Error , Error :: * , ffi :: ErrorCode :: * } , + std :: path :: * , +} ; use crate :: { collection :: * , error :: { * , ZoodexError :: * } } ; @@ -15,8 +19,10 @@ pub fn read_collection_file () -> Result { let original_name = row . get (2) ? ; let release_date = row . get (3) ? ; let runtime_minutes = row . get (4) ? ; - let poster_file_path : Option = row . get (5) ? ; - let video_file_path : Option = row . get (6) ? ; + let poster_file_path = row . get :: < _ , Option > (5) ? + . map ( PathBuf :: from ) ; + let video_file_path = row . get :: < _ , Option > (6) ? + . map ( PathBuf :: from ) ; Ok ( Film { uuid , @@ -24,8 +30,8 @@ pub fn read_collection_file () -> Result { original_name , release_date , runtime_minutes , - poster_file_path : poster_file_path . map ( String :: into ) , - video_file_path : video_file_path . map ( String :: into ) , + poster_file_path , + video_file_path , } ) } ) ; @@ -34,14 +40,10 @@ pub fn read_collection_file () -> Result { let uuid = row . get (0) ? ; let name = row . get (1) ? ; let original_name = row . get (2) ? ; - let poster_file_path : Option = row . get (3) ? ; + let poster_file_path = row . get :: < _ , Option > (3) ? + . map ( PathBuf :: from ) ; - Ok ( Series { - uuid , - name , - original_name , - poster_file_path : poster_file_path . map ( String :: into ) , - } ) + Ok ( Series { uuid , name , original_name , poster_file_path } ) } ) ; Ok ( Collection { @@ -50,10 +52,15 @@ pub fn read_collection_file () -> Result { } ) } -impl From < rusqlite :: Error > for ZoodexError { - fn from ( error : rusqlite :: Error ) -> Self { +impl From for ZoodexError { + fn from ( error : Error ) -> Self { match error { - SqliteFailure ( _ , _ ) => CollectionFileError , + SqliteFailure ( error , _ ) => { + match error . code { + Unknown => CollectionFileError , + _ => panic ! () , + } + } , _ => panic ! () , } }