Improve display of try cast exceptions

This commit is contained in:
Taylor Fausak 2021-04-17 14:17:32 +00:00 committed by GitHub
parent 634c06ca7d
commit b4c14ea8af

View File

@ -8,18 +8,21 @@ import qualified Data.Typeable as Typeable
newtype TryCastException source target
= TryCastException source
deriving (Eq, Show)
deriving Eq
instance
( Show source
, Typeable.Typeable source
, Typeable.Typeable target
) => Exception.Exception (TryCastException source target) where
displayException (TryCastException x) = mconcat
[ "TryCastException: failed to cast value "
, show x
, " from type "
, show $ Typeable.typeOf x
, " into type "
, show $ Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy target)
]
) => Show (TryCastException source target) where
showsPrec d (TryCastException x) = showParen (d > 10)
$ showString "TryCastException {- "
. shows (Typeable.typeRep (Proxy.Proxy :: Proxy.Proxy (source -> target)))
. showString " -} "
. showsPrec 11 x
instance
( Show source
, Typeable.Typeable source
, Typeable.Typeable target
) => Exception.Exception (TryCastException source target)