{-# 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
{-# INLINABLE reconstructCaseError #-}
reconstructCaseError :: Builtins.BuiltinString
reconstructCaseError :: BuiltinString
reconstructCaseError = BuiltinString
"PT1"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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