More informative error handling, more uniform sqlite column parsing
This commit is contained in:
parent
eb8a054d5c
commit
0d87993c41
2 changed files with 26 additions and 16 deletions
|
@ -9,7 +9,7 @@ use {
|
||||||
libadwaita :: { * , prelude :: * } ,
|
libadwaita :: { * , prelude :: * } ,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
use crate :: { error :: * , persistence :: * , ui :: * } ;
|
use crate :: { error :: { * , ZoodexError :: * } , persistence :: * , ui :: * } ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ fn on_activate ( app : & Application ) {
|
||||||
|
|
||||||
Ok (())
|
Ok (())
|
||||||
} , |_| () , |error| {
|
} , |_| () , |error| {
|
||||||
|
match error {
|
||||||
|
CollectionFileError => eprintln ! ("Could not open collection file") ,
|
||||||
|
} ;
|
||||||
ui . close_window () ;
|
ui . close_window () ;
|
||||||
} ) . await ;
|
} ) . await ;
|
||||||
} ) ;
|
} ) ;
|
||||||
|
|
|
@ -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 :: * } } ;
|
use crate :: { collection :: * , error :: { * , ZoodexError :: * } } ;
|
||||||
|
|
||||||
|
@ -15,8 +19,10 @@ pub fn read_collection_file () -> Result <Collection> {
|
||||||
let original_name = row . get (2) ? ;
|
let original_name = row . get (2) ? ;
|
||||||
let release_date = row . get (3) ? ;
|
let release_date = row . get (3) ? ;
|
||||||
let runtime_minutes = row . get (4) ? ;
|
let runtime_minutes = row . get (4) ? ;
|
||||||
let poster_file_path : Option <String> = row . get (5) ? ;
|
let poster_file_path = row . get :: < _ , Option <String> > (5) ?
|
||||||
let video_file_path : Option <String> = row . get (6) ? ;
|
. map ( PathBuf :: from ) ;
|
||||||
|
let video_file_path = row . get :: < _ , Option <String> > (6) ?
|
||||||
|
. map ( PathBuf :: from ) ;
|
||||||
|
|
||||||
Ok ( Film {
|
Ok ( Film {
|
||||||
uuid ,
|
uuid ,
|
||||||
|
@ -24,8 +30,8 @@ pub fn read_collection_file () -> Result <Collection> {
|
||||||
original_name ,
|
original_name ,
|
||||||
release_date ,
|
release_date ,
|
||||||
runtime_minutes ,
|
runtime_minutes ,
|
||||||
poster_file_path : poster_file_path . map ( String :: into ) ,
|
poster_file_path ,
|
||||||
video_file_path : video_file_path . map ( String :: into ) ,
|
video_file_path ,
|
||||||
} )
|
} )
|
||||||
} ) ;
|
} ) ;
|
||||||
|
|
||||||
|
@ -34,14 +40,10 @@ pub fn read_collection_file () -> Result <Collection> {
|
||||||
let uuid = row . get (0) ? ;
|
let uuid = row . get (0) ? ;
|
||||||
let name = row . get (1) ? ;
|
let name = row . get (1) ? ;
|
||||||
let original_name = row . get (2) ? ;
|
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 {
|
Ok ( Series { uuid , name , original_name , poster_file_path } )
|
||||||
uuid ,
|
|
||||||
name ,
|
|
||||||
original_name ,
|
|
||||||
poster_file_path : poster_file_path . map ( String :: into ) ,
|
|
||||||
} )
|
|
||||||
} ) ;
|
} ) ;
|
||||||
|
|
||||||
Ok ( Collection {
|
Ok ( Collection {
|
||||||
|
@ -50,10 +52,15 @@ pub fn read_collection_file () -> Result <Collection> {
|
||||||
} )
|
} )
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From < rusqlite :: Error > for ZoodexError {
|
impl From <Error> for ZoodexError {
|
||||||
fn from ( error : rusqlite :: Error ) -> Self {
|
fn from ( error : Error ) -> Self {
|
||||||
match error {
|
match error {
|
||||||
SqliteFailure ( _ , _ ) => CollectionFileError ,
|
SqliteFailure ( error , _ ) => {
|
||||||
|
match error . code {
|
||||||
|
Unknown => CollectionFileError ,
|
||||||
|
_ => panic ! () ,
|
||||||
|
}
|
||||||
|
} ,
|
||||||
_ => panic ! () ,
|
_ => panic ! () ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue