1
1
//! Errors in leetcode-cli
2
+ use crate :: cmds:: { Command , DataCommand } ;
2
3
use colored:: Colorize ;
3
4
use std:: fmt;
4
5
@@ -14,6 +15,7 @@ pub enum Error {
14
15
ScriptError ( String ) ,
15
16
CookieError ,
16
17
DecryptError ,
18
+ SilentError ,
17
19
}
18
20
19
21
impl std:: fmt:: Debug for Error {
@@ -40,6 +42,7 @@ impl std::fmt::Debug for Error {
40
42
Error :: MatchError => write ! ( f, "{} Nothing matches" , e) ,
41
43
Error :: DecryptError => write ! ( f, "{} openssl decrypt failed" , e) ,
42
44
Error :: ScriptError ( s) => write ! ( f, "{} {}" , e, s) ,
45
+ Error :: SilentError => write ! ( f, "" ) ,
43
46
}
44
47
}
45
48
}
@@ -61,7 +64,14 @@ impl std::convert::From<std::num::ParseIntError> for Error {
61
64
// sql
62
65
impl std:: convert:: From < diesel:: result:: Error > for Error {
63
66
fn from ( err : diesel:: result:: Error ) -> Self {
64
- Error :: CacheError ( err. to_string ( ) )
67
+ match err {
68
+ diesel:: result:: Error :: NotFound => {
69
+ println ! ( "NotFound, you may update cache, and try it again\r \n " ) ;
70
+ DataCommand :: usage ( ) . print_help ( ) . unwrap_or ( ( ) ) ;
71
+ Error :: SilentError
72
+ }
73
+ _ => Error :: CacheError ( err. to_string ( ) ) ,
74
+ }
65
75
}
66
76
}
67
77
0 commit comments