2019-01-26 02:45:08 +01:00
use std ::{ error ::Error as StdError , fmt , io , sync ::PoisonError } ;
2018-09-08 13:51:44 +02:00
pub type Result < T > = ::std ::result ::Result < T , Error > ;
pub enum Error {
Canonicalization ( String , io ::Error ) ,
Glob ( globset ::Error ) ,
Io ( io ::Error ) ,
Notify ( notify ::Error ) ,
2021-04-10 15:09:06 +02:00
Generic ( String ) ,
2019-01-26 02:45:08 +01:00
PoisonedLock ,
2018-09-08 13:51:44 +02:00
}
2021-04-10 15:09:06 +02:00
impl StdError for Error { }
2018-09-08 13:51:44 +02:00
2021-04-10 15:09:06 +02:00
impl From < String > for Error {
fn from ( err : String ) -> Self {
Self ::Generic ( err )
2019-01-26 02:45:08 +01:00
}
}
2018-09-08 13:51:44 +02:00
impl From < globset ::Error > for Error {
fn from ( err : globset ::Error ) -> Self {
2019-10-27 12:06:09 +01:00
Self ::Glob ( err )
2018-09-08 13:51:44 +02:00
}
}
impl From < io ::Error > for Error {
fn from ( err : io ::Error ) -> Self {
2020-07-03 14:20:02 +02:00
Self ::Io ( match err . raw_os_error ( ) {
2021-04-10 19:44:24 +02:00
Some ( 7 ) = > io ::Error ::new ( io ::ErrorKind ::Other , " There are so many changed files that the environment variables of the command have been overrun. Try running with --no-meta or --no-environment. " ) ,
_ = > err ,
2020-07-03 14:20:02 +02:00
} )
2018-09-08 13:51:44 +02:00
}
}
impl From < notify ::Error > for Error {
fn from ( err : notify ::Error ) -> Self {
match err {
2019-10-27 12:06:09 +01:00
notify ::Error ::Io ( err ) = > Self ::Io ( err ) ,
other = > Self ::Notify ( other ) ,
2018-09-08 13:51:44 +02:00
}
}
}
2019-01-26 02:45:08 +01:00
impl < ' a , T > From < PoisonError < T > > for Error {
fn from ( _err : PoisonError < T > ) -> Self {
2019-10-27 12:06:09 +01:00
Self ::PoisonedLock
2019-01-26 02:45:08 +01:00
}
}
2018-09-08 13:51:44 +02:00
impl fmt ::Display for Error {
fn fmt ( & self , f : & mut fmt ::Formatter ) -> fmt ::Result {
2019-02-15 05:02:07 +01:00
let ( error_type , error ) = match self {
2019-10-27 12:31:52 +01:00
Self ::Canonicalization ( path , err ) = > (
" Path " ,
format! ( " couldn't canonicalize ' {} ': \n {} " , path , err ) ,
) ,
2021-04-10 15:09:06 +02:00
Self ::Generic ( err ) = > ( " " , err . clone ( ) ) ,
2019-10-27 12:06:09 +01:00
Self ::Glob ( err ) = > ( " Globset " , err . to_string ( ) ) ,
Self ::Io ( err ) = > ( " I/O " , err . to_string ( ) ) ,
Self ::Notify ( err ) = > ( " Notify " , err . to_string ( ) ) ,
Self ::PoisonedLock = > ( " Internal " , " poisoned lock " . to_string ( ) ) ,
2019-02-15 05:02:07 +01:00
} ;
write! ( f , " {} error: {} " , error_type , error )
2018-09-08 13:51:44 +02:00
}
}
impl fmt ::Debug for Error {
fn fmt ( & self , f : & mut fmt ::Formatter ) -> fmt ::Result {
fmt ::Display ::fmt ( self , f )
}
}