11//! Errors in leetcode-cli
2+ use crate :: cmds:: { Command , DataCommand } ;
23use colored:: Colorize ;
34use std:: fmt;
45
@@ -14,6 +15,7 @@ pub enum Error {
1415 ScriptError ( String ) ,
1516 CookieError ,
1617 DecryptError ,
18+ SilentError ,
1719}
1820
1921impl std:: fmt:: Debug for Error {
@@ -40,6 +42,7 @@ impl std::fmt::Debug for Error {
4042 Error :: MatchError => write ! ( f, "{} Nothing matches" , e) ,
4143 Error :: DecryptError => write ! ( f, "{} openssl decrypt failed" , e) ,
4244 Error :: ScriptError ( s) => write ! ( f, "{} {}" , e, s) ,
45+ Error :: SilentError => write ! ( f, "" ) ,
4346 }
4447 }
4548}
@@ -61,7 +64,14 @@ impl std::convert::From<std::num::ParseIntError> for Error {
6164// sql
6265impl std:: convert:: From < diesel:: result:: Error > for Error {
6366 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+ }
6575 }
6676}
6777
0 commit comments