{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
module PlutusTx.ErrorCodes where

import Data.Map (Map)
import Data.Map qualified as Map
import PlutusTx.Builtins as Builtins
import Prelude (String)

{-
All error codes in this module should be unique and can be used only once!
They help to trace the errors in on-chain code.

Error codes (e.g. "PT1") become a part of the compiled contract contributing to its size,
therefore we keep them short; On the other hand, the error description isn't part of the
compiled contract, so it doesn't have to be minimal, just short enough, clear and informative.

Adding new error codes should be done without changing the existing ones:
- Add a new error code to the list `plutusPreludeErrorCodes` by incrementing the last error code.
- Add a new function with the error code name and a human-readable description.
- Update the `troubleshooting.rst` file with the new error code and its description.

When writing a new error description please follow existing patterns:
  - If an error is expected to be thrown in a specific function,
    use the fully qualified name of the function.
  - Describe the invariant which is failed.
  - Avoid using the word "error" in the description as it is redundant.
-}

{- Note [plutusPreludeErrorCodes]
   This list contains all error codes used in the plutus prelude and it is
   important that when an error code is added to the prelude it is also added
   to this list.
-}

-- | All error codes used in the plutus prelude associated with a human-readable description.
plutusPreludeErrorCodes :: Map Builtins.BuiltinString String
plutusPreludeErrorCodes :: Map BuiltinString String
plutusPreludeErrorCodes = [(BuiltinString, String)] -> Map BuiltinString String
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
  [ (BuiltinString
"PT1", String
"TH Generation of Indexed Data Error")
  , (BuiltinString
"PT2", String
"PlutusTx.IsData.Class.unsafeFromBuiltinData: Void is not supported")
  , (BuiltinString
"PT3", String
"PlutusTx.Ratio: zero denominator")
  , (BuiltinString
"PT5", String
"PlutusTx.Prelude.check: input is 'False'")
  , (BuiltinString
"PT6", String
"PlutusTx.List.!!: negative index")
  , (BuiltinString
"PT7", String
"PlutusTx.List.!!: index too large")
  , (BuiltinString
"PT8", String
"PlutusTx.List.head: empty list")
  , (BuiltinString
"PT9", String
"PlutusTx.List.tail: empty list")
  , (BuiltinString
"PT10", String
"PlutusTx.Enum.().succ: bad argument")
  , (BuiltinString
"PT11", String
"PlutusTx.Enum.().pred: bad argument")
  , (BuiltinString
"PT12", String
"PlutusTx.Enum.().toEnum: bad argument")
  , (BuiltinString
"PT13", String
"PlutusTx.Enum.Bool.succ: bad argument")
  , (BuiltinString
"PT14", String
"PlutusTx.Enum.Bool.pred: bad argument")
  , (BuiltinString
"PT15", String
"PlutusTx.Enum.Bool.toEnum: bad argument")
  , (BuiltinString
"PT16", String
"PlutusTx.Enum.Ordering.succ: bad argument")
  , (BuiltinString
"PT17", String
"PlutusTx.Enum.Ordering.pred: bad argument")
  , (BuiltinString
"PT18", String
"PlutusTx.Enum.Ordering.toEnum: bad argument")
  , (BuiltinString
"PT19", String
"PlutusTx.List.last: empty list")
  , (BuiltinString
"PT20", String
"PlutusTx.Ratio.recip: reciprocal of zero")
  , (BuiltinString
"PT21", String
"PlutusTx.List.indexBuiltinList: negative index")
  , (BuiltinString
"PT22", String
"PlutusTx.List.indexBuiltinList: index too large")
  ]

-- | The error happens in TH generation of indexed data
reconstructCaseError :: Builtins.BuiltinString
reconstructCaseError :: BuiltinString
reconstructCaseError = BuiltinString
"PT1"
{-# INLINABLE reconstructCaseError #-}

-- | Error case of 'unsafeFromBuiltinData'
voidIsNotSupportedError :: Builtins.BuiltinString
voidIsNotSupportedError :: BuiltinString
voidIsNotSupportedError = BuiltinString
"PT2"
{-# INLINABLE voidIsNotSupportedError #-}

-- | Ratio number can't have a zero denominator
ratioHasZeroDenominatorError :: Builtins.BuiltinString
ratioHasZeroDenominatorError :: BuiltinString
ratioHasZeroDenominatorError = BuiltinString
"PT3"
{-# INLINABLE ratioHasZeroDenominatorError #-}

-- | 'check' input is 'False'
checkHasFailedError :: Builtins.BuiltinString
checkHasFailedError :: BuiltinString
checkHasFailedError = BuiltinString
"PT5"
{-# INLINABLE checkHasFailedError #-}

-- | PlutusTx.List.!!: negative index
negativeIndexError :: Builtins.BuiltinString
negativeIndexError :: BuiltinString
negativeIndexError = BuiltinString
"PT6"
{-# INLINABLE negativeIndexError #-}

-- | PlutusTx.List.!!: index too large
indexTooLargeError :: Builtins.BuiltinString
indexTooLargeError :: BuiltinString
indexTooLargeError = BuiltinString
"PT7"
{-# INLINABLE indexTooLargeError #-}

-- | PlutusTx.List.head: empty list
headEmptyListError :: Builtins.BuiltinString
headEmptyListError :: BuiltinString
headEmptyListError = BuiltinString
"PT8"
{-# INLINABLE headEmptyListError #-}

-- | PlutusTx.List.tail: empty list
tailEmptyListError :: Builtins.BuiltinString
tailEmptyListError :: BuiltinString
tailEmptyListError = BuiltinString
"PT9"
{-# INLINABLE tailEmptyListError #-}

-- | PlutusTx.Enum.().succ: bad argument
succVoidBadArgumentError :: Builtins.BuiltinString
succVoidBadArgumentError :: BuiltinString
succVoidBadArgumentError = BuiltinString
"PT10"
{-# INLINABLE succVoidBadArgumentError #-}

-- | PlutusTx.Enum.().pred: bad argument
predVoidBadArgumentError :: Builtins.BuiltinString
predVoidBadArgumentError :: BuiltinString
predVoidBadArgumentError = BuiltinString
"PT11"
{-# INLINABLE predVoidBadArgumentError #-}

-- | PlutusTx.Enum.().toEnum: bad argument
toEnumVoidBadArgumentError :: Builtins.BuiltinString
toEnumVoidBadArgumentError :: BuiltinString
toEnumVoidBadArgumentError = BuiltinString
"PT12"
{-# INLINABLE toEnumVoidBadArgumentError #-}

-- | PlutusTx.Enum.Bool.succ: bad argument
succBoolBadArgumentError :: Builtins.BuiltinString
succBoolBadArgumentError :: BuiltinString
succBoolBadArgumentError = BuiltinString
"PT13"
{-# INLINABLE succBoolBadArgumentError #-}

-- | PlutusTx.Enum.Bool.pred: bad argument
predBoolBadArgumentError :: Builtins.BuiltinString
predBoolBadArgumentError :: BuiltinString
predBoolBadArgumentError = BuiltinString
"PT14"
{-# INLINABLE predBoolBadArgumentError #-}

-- | PlutusTx.Enum.Bool.toEnum: bad argument
toEnumBoolBadArgumentError :: Builtins.BuiltinString
toEnumBoolBadArgumentError :: BuiltinString
toEnumBoolBadArgumentError = BuiltinString
"PT15"
{-# INLINABLE toEnumBoolBadArgumentError #-}

-- | PlutusTx.Enum.Ordering.succ: bad argument
succOrderingBadArgumentError :: Builtins.BuiltinString
succOrderingBadArgumentError :: BuiltinString
succOrderingBadArgumentError = BuiltinString
"PT16"
{-# INLINABLE succOrderingBadArgumentError #-}

-- | PlutusTx.Enum.Ordering.pred: bad argument
predOrderingBadArgumentError :: Builtins.BuiltinString
predOrderingBadArgumentError :: BuiltinString
predOrderingBadArgumentError = BuiltinString
"PT17"
{-# INLINABLE predOrderingBadArgumentError #-}

-- | PlutusTx.Enum.Ordering.toEnum: bad argument
toEnumOrderingBadArgumentError :: Builtins.BuiltinString
toEnumOrderingBadArgumentError :: BuiltinString
toEnumOrderingBadArgumentError = BuiltinString
"PT18"
{-# INLINABLE toEnumOrderingBadArgumentError #-}

-- | PlutusTx.List.last: empty list
lastEmptyListError :: Builtins.BuiltinString
lastEmptyListError :: BuiltinString
lastEmptyListError = BuiltinString
"PT19"
{-# INLINABLE lastEmptyListError #-}

-- | PlutusTx.Ratio.recip: reciprocal of zero
reciprocalOfZeroError :: Builtins.BuiltinString
reciprocalOfZeroError :: BuiltinString
reciprocalOfZeroError = BuiltinString
"PT20"
{-# INLINABLE reciprocalOfZeroError #-}

-- | PlutusTx.List.indexBuiltinList: negative index
builtinListNegativeIndexError :: Builtins.BuiltinString
builtinListNegativeIndexError :: BuiltinString
builtinListNegativeIndexError = BuiltinString
"PT21"
{-# INLINABLE builtinListNegativeIndexError #-}

-- | PlutusTx.List.indexBuiltinList: index too large
builtinListIndexTooLargeError :: Builtins.BuiltinString
builtinListIndexTooLargeError :: BuiltinString
builtinListIndexTooLargeError = BuiltinString
"PT22"
{-# INLINABLE builtinListIndexTooLargeError #-}