module Network.IPFS.Add.Error (Error (..)) where

import           Network.IPFS.Prelude
import qualified Network.IPFS.Get.Error as Get

data Error
  = InvalidFile
  | UnexpectedOutput Text
  | RecursiveAddErr Get.Error
  | IPFSDaemonErr Text
  | UnknownAddErr Text
  deriving ( Show Error
Typeable Error
Typeable Error
-> Show Error
-> (Error -> SomeException)
-> (SomeException -> Maybe Error)
-> (Error -> String)
-> Exception Error
SomeException -> Maybe Error
Error -> String
Error -> SomeException
forall e.
Typeable e
-> Show e
-> (e -> SomeException)
-> (SomeException -> Maybe e)
-> (e -> String)
-> Exception e
displayException :: Error -> String
$cdisplayException :: Error -> String
fromException :: SomeException -> Maybe Error
$cfromException :: SomeException -> Maybe Error
toException :: Error -> SomeException
$ctoException :: Error -> SomeException
$cp2Exception :: Show Error
$cp1Exception :: Typeable Error
Exception
           , Error -> Error -> Bool
(Error -> Error -> Bool) -> (Error -> Error -> Bool) -> Eq Error
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Error -> Error -> Bool
$c/= :: Error -> Error -> Bool
== :: Error -> Error -> Bool
$c== :: Error -> Error -> Bool
Eq
           , (forall x. Error -> Rep Error x)
-> (forall x. Rep Error x -> Error) -> Generic Error
forall x. Rep Error x -> Error
forall x. Error -> Rep Error x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Error x -> Error
$cfrom :: forall x. Error -> Rep Error x
Generic
           , Int -> Error -> ShowS
[Error] -> ShowS
Error -> String
(Int -> Error -> ShowS)
-> (Error -> String) -> ([Error] -> ShowS) -> Show Error
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Error] -> ShowS
$cshowList :: [Error] -> ShowS
show :: Error -> String
$cshow :: Error -> String
showsPrec :: Int -> Error -> ShowS
$cshowsPrec :: Int -> Error -> ShowS
Show
           , [Error] -> Encoding
[Error] -> Value
Error -> Encoding
Error -> Value
(Error -> Value)
-> (Error -> Encoding)
-> ([Error] -> Value)
-> ([Error] -> Encoding)
-> ToJSON Error
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Error] -> Encoding
$ctoEncodingList :: [Error] -> Encoding
toJSONList :: [Error] -> Value
$ctoJSONList :: [Error] -> Value
toEncoding :: Error -> Encoding
$ctoEncoding :: Error -> Encoding
toJSON :: Error -> Value
$ctoJSON :: Error -> Value
ToJSON
           )

instance Display Error where
  display :: Error -> Utf8Builder
display = \case
    Error
InvalidFile          -> Utf8Builder
"Invalid file"
    UnexpectedOutput Text
txt -> Utf8Builder
"Unexpected IPFS output: " Utf8Builder -> Utf8Builder -> Utf8Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Utf8Builder
forall a. Display a => a -> Utf8Builder
display Text
txt
    RecursiveAddErr  Error
err -> Utf8Builder
"Error while adding directory" Utf8Builder -> Utf8Builder -> Utf8Builder
forall a. Semigroup a => a -> a -> a
<> Error -> Utf8Builder
forall a. Display a => a -> Utf8Builder
display Error
err
    IPFSDaemonErr    Text
txt -> Utf8Builder
"IPFS Daemon error: " Utf8Builder -> Utf8Builder -> Utf8Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Utf8Builder
forall a. Display a => a -> Utf8Builder
display Text
txt
    UnknownAddErr    Text
txt -> Utf8Builder
"Unknown IPFS add error: " Utf8Builder -> Utf8Builder -> Utf8Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Utf8Builder
forall a. Display a => a -> Utf8Builder
display Text
txt