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 ) ,
2019-01-26 02:45:08 +01:00
Clap ( clap ::Error ) ,
2018-09-08 13:51:44 +02:00
Glob ( globset ::Error ) ,
Io ( io ::Error ) ,
Notify ( notify ::Error ) ,
2019-01-26 02:45:08 +01:00
PoisonedLock ,
2018-09-08 13:51:44 +02:00
}
2018-09-09 00:38:07 +02:00
impl StdError for Error {
2018-10-05 09:56:06 +02:00
fn description ( & self ) -> & str {
2018-09-09 00:38:07 +02:00
// This method is soft-deprecated and shouldn't be used,
// see Display for the actual description.
" a watchexec error "
}
}
2018-09-08 13:51:44 +02:00
2019-01-26 02:45:08 +01:00
impl From < clap ::Error > for Error {
fn from ( err : clap ::Error ) -> Self {
2019-10-27 12:06:09 +01:00
Self ::Clap ( 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-06-24 13:40:11 +02:00
Self ::Io (
match err . raw_os_error ( ) {
Some ( os_err ) = > match os_err {
7 = > {
let msg = " There are so many changed files that the environment variables of the child process have been overrun. Try running with --no-meta or --no-environment. " ;
io ::Error ::new ( io ::ErrorKind ::Other , msg )
} ,
_ = > err ,
}
None = > err ,
}
)
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 ) ,
) ,
2019-10-27 12:06:09 +01:00
Self ::Clap ( err ) = > ( " Argument " , err . to_string ( ) ) ,
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 )
}
}