File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 1- use std:: { error :: Error , fmt:: Debug , fs:: read_to_string, path:: PathBuf } ;
1+ use std:: { fmt:: Debug , fs:: read_to_string, path:: PathBuf } ;
22
3+ use color_eyre:: eyre:: { eyre, Result } ;
34use serde:: Deserialize ;
45
56use crate :: otp:: otp_element:: OTPElement ;
67
78/// Common flow for all the importers
8- pub fn import_from_path < T > ( path : PathBuf ) -> Result < Vec < OTPElement > , Box < dyn Error > >
9+ pub fn import_from_path < T > ( path : PathBuf ) -> Result < Vec < OTPElement > >
910where
1011 T : for < ' a > Deserialize < ' a > + TryInto < Vec < OTPElement > > ,
1112 <T as TryInto < Vec < OTPElement > > >:: Error : Debug ,
1213{
1314 let json = read_to_string ( path) ?;
14- let deserialized: T = serde_json:: from_str ( json. as_str ( ) ) . map_err ( |e| e. to_string ( ) ) ?;
15- let mapped: Vec < OTPElement > = deserialized. try_into ( ) . map_err ( |e| format ! ( "{:?}" , e) ) ?;
15+ let deserialized: T = serde_json:: from_str ( json. as_str ( ) ) . map_err ( |e| {
16+ eyre ! (
17+ "Invalid JSON import format.
18+ Please check the file you are trying to import. For further information please check these guidelines:
19+ https://github.com/replydev/cotp?tab=readme-ov-file#migration-from-other-apps
20+
21+ Specific error: {:?}" ,
22+ e
23+ )
24+ } ) ?;
25+ let mapped: Vec < OTPElement > = deserialized. try_into ( ) . map_err ( |e| eyre ! ( "{:?}" , e) ) ?;
1626 Ok ( mapped)
1727}
You can’t perform that action at this time.
0 commit comments