hydra-plutus
Safe HaskellSafe-Inferred
LanguageGHC2021

Hydra.Contract.Error

Description

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

Documentation

class ToErrorCode a where Source #

Types which are used to describe errors as short error codes in scripts.

Methods

toErrorCode :: a -> Text Source #

Get the short error code used in a script for given type.

Instances

Instances details
ToErrorCode DepositError Source # 
Instance details

Defined in Hydra.Contract.DepositError

Methods

toErrorCode :: DepositError -> Text Source #

ToErrorCode HeadError Source # 
Instance details

Defined in Hydra.Contract.HeadError

Methods

toErrorCode :: HeadError -> Text Source #

ToErrorCode HeadTokensError Source # 
Instance details

Defined in Hydra.Contract.HeadTokensError

ToErrorCode UtilError Source # 
Instance details

Defined in Hydra.Contract.UtilError

Methods

toErrorCode :: UtilError -> Text Source #

errorCode :: ToErrorCode e => e -> Q Exp Source #

Get the string literal from given error e. Use this with template haskell splices, e.g. $(errorCode MyError)