{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.Type.Error.ProtocolParamsError
  ( ProtocolParamsError (..)
  , renderProtocolParamsError
  )
where

import Cardano.Api

import Data.Text (Text)

data ProtocolParamsError
  = ProtocolParamsErrorFile (FileError ())
  | ProtocolParamsErrorJSON !FilePath !Text
  deriving Int -> ProtocolParamsError -> ShowS
[ProtocolParamsError] -> ShowS
ProtocolParamsError -> String
(Int -> ProtocolParamsError -> ShowS)
-> (ProtocolParamsError -> String)
-> ([ProtocolParamsError] -> ShowS)
-> Show ProtocolParamsError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProtocolParamsError -> ShowS
showsPrec :: Int -> ProtocolParamsError -> ShowS
$cshow :: ProtocolParamsError -> String
show :: ProtocolParamsError -> String
$cshowList :: [ProtocolParamsError] -> ShowS
showList :: [ProtocolParamsError] -> ShowS
Show

instance Error ProtocolParamsError where
  prettyError :: forall ann. ProtocolParamsError -> Doc ann
prettyError = ProtocolParamsError -> Doc ann
forall ann. ProtocolParamsError -> Doc ann
renderProtocolParamsError

renderProtocolParamsError :: ProtocolParamsError -> Doc ann
renderProtocolParamsError :: forall ann. ProtocolParamsError -> Doc ann
renderProtocolParamsError = \case
  ProtocolParamsErrorFile FileError ()
fileErr ->
    FileError () -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. FileError () -> Doc ann
prettyError FileError ()
fileErr
  ProtocolParamsErrorJSON String
fp Text
jsonErr ->
    Doc ann
"Error while decoding the protocol parameters at: " 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
fp Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
" Error: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Text -> Doc ann
forall a ann. Show a => a -> Doc ann
pshow Text
jsonErr