Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Error codes to be used in plutus scripts.
Define a new type and instantiate ToErrorCode
for error cases you want to
use in scripts.
data MyError = CaseA | CaseB deriving Show instance ToErrorCode MyError where toErrorCode = case CaseA -> CA CaseB -> CB
In plutus-tx, you can then use template haskell to inline the error codes using the '$(errorCode ..)' splice.
validator = traceError $(errorCode CaseA)
This example will have your validator fail with user error CA, which you can match for using 'toErrorCode CaseA' in Haskell.
Synopsis
- class ToErrorCode a where
- toErrorCode :: a -> Text
- errorCode :: ToErrorCode e => e -> Q Exp
Documentation
class ToErrorCode a where Source #
Types which are used to describe errors as short error codes in scripts.
toErrorCode :: a -> Text Source #
Get the short error code used in a script for given type.
Instances
ToErrorCode CommitError Source # | |
Defined in Hydra.Contract.CommitError toErrorCode :: CommitError -> Text Source # | |
ToErrorCode DepositError Source # | |
Defined in Hydra.Contract.DepositError toErrorCode :: DepositError -> Text Source # | |
ToErrorCode HeadError Source # | |
Defined in Hydra.Contract.HeadError toErrorCode :: HeadError -> Text Source # | |
ToErrorCode HeadTokensError Source # | |
Defined in Hydra.Contract.HeadTokensError toErrorCode :: HeadTokensError -> Text Source # | |
ToErrorCode InitialError Source # | |
Defined in Hydra.Contract.InitialError toErrorCode :: InitialError -> Text Source # | |
ToErrorCode UtilError Source # | |
Defined in Hydra.Contract.Util toErrorCode :: UtilError -> Text Source # |