module Currycarbon.Utils (
    CurrycarbonException (..),
    renderCurrycarbonException
) where

import           Control.Exception (Exception)

-- | Different exceptions for currycarbon
data CurrycarbonException =
    -- | An exception to describe an issue in the currycarbon CLI input parsing
      CurrycarbonCLIParsingException String
    -- | An exception to describe the case that a date is not in the range of
    -- the supplied calibration curve
    | CurrycarbonCalibrationRangeException String
    -- | An exception for CalPDFs that are unsuitable for certain purposes
    | CurrycarbonInvalidCalPDFException String
    -- | An exception for any issues with the CLI
    | CurrycarbonCLIException String
    deriving (Int -> CurrycarbonException -> ShowS
[CurrycarbonException] -> ShowS
CurrycarbonException -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CurrycarbonException] -> ShowS
$cshowList :: [CurrycarbonException] -> ShowS
show :: CurrycarbonException -> String
$cshow :: CurrycarbonException -> String
showsPrec :: Int -> CurrycarbonException -> ShowS
$cshowsPrec :: Int -> CurrycarbonException -> ShowS
Show)

instance Exception CurrycarbonException

renderCurrycarbonException :: CurrycarbonException -> String
renderCurrycarbonException :: CurrycarbonException -> String
renderCurrycarbonException (CurrycarbonCLIParsingException String
s) =
    String
"<!> Error: Input can not be parsed\n" forall a. [a] -> [a] -> [a]
++ String
s
renderCurrycarbonException (CurrycarbonCalibrationRangeException String
i) =
    String
"<!> Error: Date outside of calibration range. Date ID: " forall a. [a] -> [a] -> [a]
++ String
i
renderCurrycarbonException (CurrycarbonInvalidCalPDFException String
o) =
    String
"<!> Error: Invalid CalPDF for " forall a. [a] -> [a] -> [a]
++ String
o forall a. [a] -> [a] -> [a]
++
    String
", either because all densities are 0 or one density is > 1"
renderCurrycarbonException (CurrycarbonCLIException String
s) =
    String
"<!> Error: " forall a. [a] -> [a] -> [a]
++ String
s