{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Cardano.CLI.Types.Errors.NodeCmdError
  ( NodeCmdError (..)
  , renderNodeCmdError
  )
where

import           Cardano.Api

{- HLINT ignore "Reduce duplication" -}

data NodeCmdError
  = NodeCmdReadFileError !(FileError TextEnvelopeError)
  | NodeCmdReadKeyFileError !(FileError InputDecodeError)
  | NodeCmdWriteFileError !(FileError ())
  | NodeCmdOperationalCertificateIssueError !OperationalCertIssueError
  | NodeCmdVrfSigningKeyCreationError
      FilePath
      -- ^ Target path
      FilePath
      -- ^ Temp path
  deriving Int -> NodeCmdError -> ShowS
[NodeCmdError] -> ShowS
NodeCmdError -> String
(Int -> NodeCmdError -> ShowS)
-> (NodeCmdError -> String)
-> ([NodeCmdError] -> ShowS)
-> Show NodeCmdError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> NodeCmdError -> ShowS
showsPrec :: Int -> NodeCmdError -> ShowS
$cshow :: NodeCmdError -> String
show :: NodeCmdError -> String
$cshowList :: [NodeCmdError] -> ShowS
showList :: [NodeCmdError] -> ShowS
Show

renderNodeCmdError :: NodeCmdError -> Doc ann
renderNodeCmdError :: forall ann. NodeCmdError -> Doc ann
renderNodeCmdError = \case
  NodeCmdVrfSigningKeyCreationError String
targetPath String
tempPath ->
    Doc ann
"Error creating VRF signing key file. Target path: "
      Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> String -> Doc ann
forall a ann. Show a => a -> Doc ann
pshow String
targetPath
      Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" Temporary path: "
      Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> String -> Doc ann
forall a ann. Show a => a -> Doc ann
pshow String
tempPath
  NodeCmdReadFileError FileError TextEnvelopeError
fileErr ->
    FileError TextEnvelopeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError TextEnvelopeError -> Doc ann
prettyError FileError TextEnvelopeError
fileErr
  NodeCmdReadKeyFileError FileError InputDecodeError
fileErr ->
    FileError InputDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError InputDecodeError -> Doc ann
prettyError FileError InputDecodeError
fileErr
  NodeCmdWriteFileError FileError ()
fileErr ->
    FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
fileErr
  NodeCmdOperationalCertificateIssueError OperationalCertIssueError
issueErr ->
    OperationalCertIssueError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. OperationalCertIssueError -> Doc ann
prettyError OperationalCertIssueError
issueErr