@ -85,14 +85,18 @@ impl ErrorKind {
#[ derive(Debug, Clone) ]
pub struct MeliError {
pub summary : Option < Cow< ' static , str > > ,
pub details : Cow< ' static , str > ,
pub summary : Cow< ' static , str > ,
pub details : Option < Cow< ' static , str > > ,
pub source : Option < std ::sync ::Arc < dyn Error + Send + Sync + ' static > > ,
pub kind : ErrorKind ,
}
pub trait IntoMeliError {
fn set_err_summary < M > ( self , msg : M ) -> MeliError
where
M : Into < Cow < ' static , str > > ;
fn set_err_details < M > ( self , msg : M ) -> MeliError
where
M : Into < Cow < ' static , str > > ;
fn set_err_kind ( self , kind : ErrorKind ) -> MeliError ;
@ -117,6 +121,15 @@ impl<I: Into<MeliError>> IntoMeliError for I {
err . set_summary ( msg )
}
#[ inline ]
fn set_err_details < M > ( self , msg : M ) -> MeliError
where
M : Into < Cow < ' static , str > > ,
{
let err : MeliError = self . into ( ) ;
err . set_details ( msg )
}
#[ inline ]
fn set_err_kind ( self , kind : ErrorKind ) -> MeliError {
let err : MeliError = self . into ( ) ;
@ -146,21 +159,33 @@ impl MeliError {
M : Into < Cow < ' static , str > > ,
{
MeliError {
summary : None ,
details : msg . into ( ) ,
summary : msg . into ( ) ,
details : None ,
source : None ,
kind : ErrorKind ::None ,
}
}
pub fn set_details < M > ( mut self , details : M ) -> MeliError
where
M : Into < Cow < ' static , str > > ,
{
if let Some ( old_details ) = self . details . as_ref ( ) {
self . details = Some ( format! ( "{}. {}" , old_details , details . into ( ) ) . into ( ) ) ;
} else {
self . details = Some ( details . into ( ) ) ;
}
self
}
pub fn set_summary < M > ( mut self , summary : M ) -> MeliError
where
M : Into < Cow < ' static , str > > ,
{
if let Some ( old_summary ) = self . summary . take ( ) {
self . summary = Some ( format! ( "{}. {}" , old_summary , summary . into ( ) ) . into ( ) ) ;
if self . summary . is_empty ( ) {
self . summary = summary . into ( ) ;
} else {
self . summary = Some ( summary . into ( ) ) ;
self . summary = format! ( "{}. {}" , self . summary , summary . into ( ) ) . into ( ) ;
}
self
}
@ -181,10 +206,10 @@ impl MeliError {
impl fmt ::Display for MeliError {
fn fmt ( & self , f : & mut fmt ::Formatter ) -> fmt ::Result {
if let Some ( summary ) = self . summary . as_ref ( ) {
writeln! ( f , "Summary: {}" , summary ) ? ;
writeln! ( f , "Summary: {}" , self . summary ) ? ;
if let Some ( details ) = self . details . as_ref ( ) {
write! ( f , "{}" , details ) ? ;
}
write! ( f , "{}" , self . details ) ? ;
if let Some ( source ) = self . source . as_ref ( ) {
write! ( f , "\nCaused by: {}" , source ) ? ;
}
@ -205,7 +230,7 @@ impl From<io::Error> for MeliError {
#[ inline ]
fn from ( kind : io ::Error ) -> MeliError {
MeliError ::new ( kind . to_string ( ) )
. set_ summary( format! ( "{:?}" , kind . kind ( ) ) )
. set_ details( kind . kind ( ) . to_string ( ) )
. set_source ( Some ( Arc ::new ( kind ) ) )
. set_kind ( ErrorKind ::OSError )
}
@ -214,21 +239,21 @@ impl From<io::Error> for MeliError {
impl < ' a > From < Cow < ' a , str > > for MeliError {
#[ inline ]
fn from ( kind : Cow < ' _ , str > ) -> MeliError {
MeliError ::new ( format! ( "{:?}" , kind ) )
MeliError ::new ( kind . to_string ( ) )
}
}
impl From < string ::FromUtf8Error > for MeliError {
#[ inline ]
fn from ( kind : string ::FromUtf8Error ) -> MeliError {
MeliError ::new ( format! ( "{:?}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
impl From < str ::Utf8Error > for MeliError {
#[ inline ]
fn from ( kind : str ::Utf8Error ) -> MeliError {
MeliError ::new ( format! ( "{:?}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
//use std::option;
@ -242,7 +267,7 @@ impl From<str::Utf8Error> for MeliError {
impl < T > From < std ::sync ::PoisonError < T > > for MeliError {
#[ inline ]
fn from ( kind : std ::sync ::PoisonError < T > ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) )
MeliError ::new ( kind . to_string ( ) ) . set_kind ( ErrorKind ::Bug )
}
}
@ -252,7 +277,9 @@ impl<T: Sync + Send + 'static + core::fmt::Debug> From<native_tls::HandshakeErro
{
#[ inline ]
fn from ( kind : native_tls ::HandshakeError < T > ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) )
. set_source ( Some ( Arc ::new ( kind ) ) )
. set_kind ( ErrorKind ::Network )
}
}
@ -260,14 +287,16 @@ impl<T: Sync + Send + 'static + core::fmt::Debug> From<native_tls::HandshakeErro
impl From < native_tls ::Error > for MeliError {
#[ inline ]
fn from ( kind : native_tls ::Error ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) )
. set_source ( Some ( Arc ::new ( kind ) ) )
. set_kind ( ErrorKind ::Network )
}
}
impl From < std ::num ::ParseIntError > for MeliError {
#[ inline ]
fn from ( kind : std ::num ::ParseIntError ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
@ -283,35 +312,35 @@ impl From<isahc::Error> for MeliError {
impl From < serde_json ::error ::Error > for MeliError {
#[ inline ]
fn from ( kind : serde_json ::error ::Error ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
impl From < Box < dyn Error + Sync + Send + ' static > > for MeliError {
#[ inline ]
fn from ( kind : Box < dyn Error + Sync + Send + ' static > ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( kind . into ( ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( kind . into ( ) ) )
}
}
impl From < std ::ffi ::NulError > for MeliError {
#[ inline ]
fn from ( kind : std ::ffi ::NulError ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
impl From < Box < bincode ::ErrorKind > > for MeliError {
#[ inline ]
fn from ( kind : Box < bincode ::ErrorKind > ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
impl From < nix ::Error > for MeliError {
#[ inline ]
fn from ( kind : nix ::Error ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
@ -319,14 +348,14 @@ impl From<nix::Error> for MeliError {
impl From < rusqlite ::Error > for MeliError {
#[ inline ]
fn from ( kind : rusqlite ::Error ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
impl From < libloading ::Error > for MeliError {
#[ inline ]
fn from ( kind : libloading ::Error ) -> MeliError {
MeliError ::new ( format! ( "{}" , kind ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
MeliError ::new ( kind . to_string ( ) ) . set_source ( Some ( Arc ::new ( kind ) ) )
}
}
@ -347,16 +376,14 @@ impl From<String> for MeliError {
impl From < nom ::Err < ( & [ u8 ] , nom ::error ::ErrorKind ) > > for MeliError {
#[ inline ]
fn from ( kind : nom ::Err < ( & [ u8 ] , nom ::error ::ErrorKind ) > ) -> MeliError {
MeliError ::new ( "Parsing error" )
. set_source ( Some ( Arc ::new ( MeliError ::new ( format! ( "{}" , kind ) ) ) ) )
MeliError ::new ( "Parsing error" ) . set_source ( Some ( Arc ::new ( MeliError ::new ( kind . to_string ( ) ) ) ) )
}
}
impl From < nom ::Err < ( & str , nom ::error ::ErrorKind ) > > for MeliError {
#[ inline ]
fn from ( kind : nom ::Err < ( & str , nom ::error ::ErrorKind ) > ) -> MeliError {
MeliError ::new ( "Parsing error" )
. set_source ( Some ( Arc ::new ( MeliError ::new ( format! ( "{}" , kind ) ) ) ) )
MeliError ::new ( "Parsing error" ) . set_details ( kind . to_string ( ) )
}
}