{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Types.Errors.GovernanceCommitteeError
  ( GovernanceCommitteeError (..)
  )
where

import           Cardano.Api

import           Cardano.CLI.Types.Errors.HashCmdError (HashCheckError)
import           Cardano.CLI.Types.Errors.ScriptDecodeError

import           Control.Exception (displayException)

data GovernanceCommitteeError
  = GovernanceCommitteeCmdKeyDecodeError InputDecodeError
  | GovernanceCommitteeCmdKeyReadError (FileError InputDecodeError)
  | GovernanceCommitteeCmdScriptReadError (FileError ScriptDecodeError)
  | GovernanceCommitteeCmdTextEnvReadFileError (FileError TextEnvelopeError)
  | GovernanceCommitteeCmdTextEnvWriteError (FileError ())
  | GovernanceCommitteeCmdWriteFileError (FileError ())
  | GovernanceCommitteeHashCheckError !HashCheckError
  deriving Int -> GovernanceCommitteeError -> ShowS
[GovernanceCommitteeError] -> ShowS
GovernanceCommitteeError -> String
(Int -> GovernanceCommitteeError -> ShowS)
-> (GovernanceCommitteeError -> String)
-> ([GovernanceCommitteeError] -> ShowS)
-> Show GovernanceCommitteeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GovernanceCommitteeError -> ShowS
showsPrec :: Int -> GovernanceCommitteeError -> ShowS
$cshow :: GovernanceCommitteeError -> String
show :: GovernanceCommitteeError -> String
$cshowList :: [GovernanceCommitteeError] -> ShowS
showList :: [GovernanceCommitteeError] -> ShowS
Show

instance Error GovernanceCommitteeError where
  prettyError :: forall ann. GovernanceCommitteeError -> Doc ann
prettyError = \case
    GovernanceCommitteeCmdKeyDecodeError InputDecodeError
e ->
      Doc ann
"Cannot decode key: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> InputDecodeError -> Doc ann
forall ann. InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
prettyError InputDecodeError
e
    GovernanceCommitteeCmdKeyReadError FileError InputDecodeError
e ->
      Doc ann
"Cannot read key: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError InputDecodeError -> Doc ann
prettyError FileError InputDecodeError
e
    GovernanceCommitteeCmdWriteFileError FileError ()
e ->
      Doc ann
"Cannot write file: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
e
    GovernanceCommitteeCmdTextEnvReadFileError FileError TextEnvelopeError
e ->
      Doc ann
"Cannot read text envelope file: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError TextEnvelopeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError TextEnvelopeError -> Doc ann
prettyError FileError TextEnvelopeError
e
    GovernanceCommitteeCmdTextEnvWriteError FileError ()
e ->
      Doc ann
"Cannot write text envelope file: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
e
    GovernanceCommitteeCmdScriptReadError FileError ScriptDecodeError
e ->
      Doc ann
"Cannot read script file: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> FileError ScriptDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError ScriptDecodeError -> Doc ann
prettyError FileError ScriptDecodeError
e
    GovernanceCommitteeHashCheckError HashCheckError
hashCheckErr ->
      Doc ann
"Error while checking metadata hash: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> String -> Doc ann
forall ann. String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (HashCheckError -> String
forall e. Exception e => e -> String
displayException HashCheckError
hashCheckErr)