{-# LANGUAGE LambdaCase #-}

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

import           Cardano.Api

--
-- Handling decoding the variety of script languages and formats
--

data ScriptDecodeError
  = ScriptDecodeTextEnvelopeError TextEnvelopeError
  | ScriptDecodeSimpleScriptError JsonDecodeError
  deriving Int -> ScriptDecodeError -> ShowS
[ScriptDecodeError] -> ShowS
ScriptDecodeError -> String
(Int -> ScriptDecodeError -> ShowS)
-> (ScriptDecodeError -> String)
-> ([ScriptDecodeError] -> ShowS)
-> Show ScriptDecodeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScriptDecodeError -> ShowS
showsPrec :: Int -> ScriptDecodeError -> ShowS
$cshow :: ScriptDecodeError -> String
show :: ScriptDecodeError -> String
$cshowList :: [ScriptDecodeError] -> ShowS
showList :: [ScriptDecodeError] -> ShowS
Show

instance Error ScriptDecodeError where
  prettyError :: forall ann. ScriptDecodeError -> Doc ann
prettyError = \case
    ScriptDecodeTextEnvelopeError TextEnvelopeError
err ->
      Doc ann
"Error decoding script: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> TextEnvelopeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. TextEnvelopeError -> Doc ann
prettyError TextEnvelopeError
err
    ScriptDecodeSimpleScriptError JsonDecodeError
err ->
      Doc ann
"Syntax error in script: " Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> JsonDecodeError -> Doc ann
forall e ann. Error e => e -> Doc ann
forall ann. JsonDecodeError -> Doc ann
prettyError JsonDecodeError
err