More informative error handling, more uniform sqlite column parsing

This commit is contained in:
Reinout Meliesie 2024-11-30 14:38:08 +01:00
parent eb8a054d5c
commit 0d87993c41
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 26 additions and 16 deletions

View file

@ -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 ;
} ) ;

View file

@ -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 <Collection> {
let original_name = row . get (2) ? ;
let release_date = row . get (3) ? ;
let runtime_minutes = row . get (4) ? ;
let poster_file_path : Option <String> = row . get (5) ? ;
let video_file_path : Option <String> = row . get (6) ? ;
let poster_file_path = row . get :: < _ , Option <String> > (5) ?
. map ( PathBuf :: from ) ;
let video_file_path = row . get :: < _ , Option <String> > (6) ?
. map ( PathBuf :: from ) ;
Ok ( Film {
uuid ,
@ -24,8 +30,8 @@ pub fn read_collection_file () -> Result <Collection> {
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 <Collection> {
let uuid = row . get (0) ? ;
let name = row . get (1) ? ;
let original_name = row . get (2) ? ;
let poster_file_path : Option <String> = row . get (3) ? ;
let poster_file_path = row . get :: < _ , Option <String> > (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 <Collection> {
} )
}
impl From < rusqlite :: Error > for ZoodexError {
fn from ( error : rusqlite :: Error ) -> Self {
impl From <Error> for ZoodexError {
fn from ( error : Error ) -> Self {
match error {
SqliteFailure ( _ , _ ) => CollectionFileError ,
SqliteFailure ( error , _ ) => {
match error . code {
Unknown => CollectionFileError ,
_ => panic ! () ,
}
} ,
_ => panic ! () ,
}
}