Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class ErrorHasDoc e => IsError e where
- errorToVal :: e -> (forall t. ErrorScope t => Value t -> r) -> r
- errorFromVal :: SingI t => Value t -> Either Text e
- failUsing :: IsError e => e -> s :-> t
- type ErrorScope t = ConstantScope t
- class (SingI t, WellTyped t, HasNoOp t, HasNoBigMap t, HasNoContract t, HasNoTicket t, HasNoSaplingState t) => ConstantScope (t :: T)
- isoErrorToVal :: (KnownError e, IsoValue e) => e -> (forall t. ErrorScope t => Value t -> r) -> r
- isoErrorFromVal :: (SingI t, KnownIsoT e, IsoValue e) => Value t -> Either Text e
- simpleFailUsing :: forall e s t. IsError e => e -> s :-> t
- class Typeable e => ErrorHasDoc (e :: Type) where
- typeDocMdDescriptionReferToError :: forall e. IsError e => Markdown
- isInternalErrorClass :: ErrorClass -> Bool
- data UnspecifiedError = UnspecifiedError
- data Impossible (reason :: Symbol) = HasCallStack => Impossible
- data SomeError = forall e.(IsError e, Eq e) => SomeError e
- failUnexpected :: MText -> s :-> t
- data NoErrorArg
- data UnitErrorArg
- type family ErrorArg (tag :: Symbol) :: Type
- data CustomError (tag :: Symbol) = CustomError {
- ceTag :: Label tag
- ceArg :: CustomErrorRep tag
- type CustomErrorRep tag = CustomErrorArgRep (ErrorArg tag)
- class IsCustomErrorArgRep a where
- verifyErrorTag :: MText -> a -> Either Text a
- customErrorRepDocDeps :: [SomeDocDefinitionItem]
- customErrorHaskellRep :: (KnownSymbol tag, CustomErrorHasDoc tag) => Proxy tag -> Markdown
- type MustHaveErrorArg errorTag expectedArgRep = (AssertTypesEqual (CustomErrorRep errorTag) expectedArgRep ((('Text "Error argument type is " :<>: 'ShowType expectedArgRep) :<>: 'Text " but given error requires argument of type ") :<>: 'ShowType (CustomErrorRep errorTag)), CustomErrorRep errorTag ~ expectedArgRep)
- failCustom :: forall tag err s any. (MustHaveErrorArg tag (MText, err), CustomErrorHasDoc tag, KnownError err) => Label tag -> (err ': s) :-> any
- failCustom_ :: forall tag s any. (MustHaveErrorArg tag (MText, ()), CustomErrorHasDoc tag) => Label tag -> s :-> any
- failCustomNoArg :: forall tag s any. (MustHaveErrorArg tag MText, CustomErrorHasDoc tag) => Label tag -> s :-> any
- data ErrorClass
- class (KnownSymbol tag, TypeHasDoc (CustomErrorRep tag), IsError (CustomError tag)) => CustomErrorHasDoc tag where
- data DError where
- DError :: ErrorHasDoc e => Proxy e -> DError
- data DThrows where
- DThrows :: ErrorHasDoc e => Proxy e -> DThrows
- errorTagToText :: forall tag. KnownSymbol tag => Text
- errorTagToMText :: Label tag -> MText
Haskell to Value
conversion
class ErrorHasDoc e => IsError e where Source #
Haskell type representing error.
errorToVal :: e -> (forall t. ErrorScope t => Value t -> r) -> r Source #
Converts a Haskell error into Value
representation.
errorFromVal :: SingI t => Value t -> Either Text e Source #
Converts a Value
into Haskell error.
failUsing :: IsError e => e -> s :-> t Source #
Fail with the given Haskell value.
Instances
(TypeError ('Text "Use representative error messages") :: Constraint) => IsError () Source # | |
Defined in Lorentz.Errors | |
IsError MText Source # | Use this for internal errors only. "Normal" error scenarios should use the mechanism of custom errors, see below. |
IsError UnspecifiedError Source # | |
Defined in Lorentz.Errors errorToVal :: UnspecifiedError -> (forall (t :: T). ErrorScope t => Value t -> r) -> r Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text UnspecifiedError Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError UnspecifiedError => UnspecifiedError -> s :-> t Source # | |
(CustomErrorHasDoc tag, KnownError (CustomErrorRep tag), IsoValue (CustomErrorRep tag), IsCustomErrorArgRep (CustomErrorRep tag)) => IsError (CustomError tag) Source # | |
Defined in Lorentz.Errors errorToVal :: CustomError tag -> (forall (t :: T). ErrorScope t => Value t -> r) -> r Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text (CustomError tag) Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError (CustomError tag) => CustomError tag -> s :-> t Source # | |
KnownSymbol reason => IsError (Impossible reason) Source # | |
Defined in Lorentz.Errors errorToVal :: Impossible reason -> (forall (t :: T). ErrorScope t => Value t -> r) -> r Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text (Impossible reason) Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError (Impossible reason) => Impossible reason -> s :-> t Source # | |
(NiceConstant r, ErrorHasDoc (VoidResult r)) => IsError (VoidResult r) Source # | |
Defined in Lorentz.Macro errorToVal :: VoidResult r -> (forall (t :: T). ErrorScope t => Value t -> r0) -> r0 Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text (VoidResult r) Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError (VoidResult r) => VoidResult r -> s :-> t Source # | |
(Typeable arg, IsError (CustomError tag), AssertTypesEqual arg () notVoidError, arg ~ ErrorArg tag, notVoidError ~ ('Text "This error requires argument of type " :<>: 'ShowType (ErrorArg tag))) => IsError (arg -> CustomError tag) Source # | If |
Defined in Lorentz.Errors errorToVal :: (arg -> CustomError tag) -> (forall (t :: T). ErrorScope t => Value t -> r) -> r Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text (arg -> CustomError tag) Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError (arg -> CustomError tag) => (arg -> CustomError tag) -> s :-> t Source # |
type ErrorScope t = ConstantScope t Source #
Since 008 it's prohibited to fail with non-packable values and with the
'Contract t' type values, which is equivalent to our ConstantScope
constraint.
See https://gitlab.com/tezos/tezos/-/issues/1093#note_496066354 for more information.
class (SingI t, WellTyped t, HasNoOp t, HasNoBigMap t, HasNoContract t, HasNoTicket t, HasNoSaplingState t) => ConstantScope (t :: T) #
Instances
(SingI t, WellTyped t, HasNoOp t, HasNoBigMap t, HasNoContract t, HasNoTicket t, HasNoSaplingState t) => ConstantScope t | |
Defined in Morley.Michelson.Typed.Scope | |
(WithDeMorganScope HasNoOp t a b, WithDeMorganScope HasNoBigMap t a b, WithDeMorganScope HasNoContract t a b, WithDeMorganScope HasNoTicket t a b, WithDeMorganScope HasNoSaplingState t a b, SingI a, SingI b, WellTyped a, WellTyped b) => WithDeMorganScope ConstantScope t a b | |
Defined in Morley.Michelson.Typed.Scope withDeMorganScope :: ConstantScope (t a b) => ((ConstantScope a, ConstantScope b) => ret) -> ret | |
SingI t => CheckScope (ConstantScope t) | |
Defined in Morley.Michelson.Typed.Scope checkScope :: Either BadTypeForScope (Dict (ConstantScope t)) |
isoErrorToVal :: (KnownError e, IsoValue e) => e -> (forall t. ErrorScope t => Value t -> r) -> r Source #
Implementation of errorToVal
via IsoValue
.
isoErrorFromVal :: (SingI t, KnownIsoT e, IsoValue e) => Value t -> Either Text e Source #
Implementation of errorFromVal
via IsoValue
.
simpleFailUsing :: forall e s t. IsError e => e -> s :-> t Source #
Basic implementation for failUsing
.
class Typeable e => ErrorHasDoc (e :: Type) where Source #
type ErrorRequirements e :: Constraint Source #
Constraints which we require in a particular instance. You are not oblidged to often instantiate this correctly, it is only useful for some utilities.
type ErrorRequirements _ = ()
errorDocName :: Text Source #
Name of error as it appears in the corresponding section title.
errorDocMdCause :: Markdown Source #
What should happen for this error to be raised.
errorDocMdCauseInEntrypoint :: Markdown Source #
Brief version of errorDocMdCause
.
This will appear along with the error when mentioned in entrypoint description. By default, the first sentence of the full description is used.
errorDocHaskellRep :: Markdown Source #
How this error is represented in Haskell.
errorDocClass :: ErrorClass Source #
Error class.
errorDocDependencies :: [SomeDocDefinitionItem] Source #
Which definitions documentation for this error mentions.
errorDocRequirements :: Dict (ErrorRequirements e) Source #
Captured constraints which we require in a particular instance.
This is a way to encode a bidirectional instance in the nowaday Haskell,
for class MyConstraint => ErrorHasDoc MyType
instance it lets deducing
MyConstraint
by ErrorHasDoc MyType
.
You are not oblidged to always instantiate, it is only useful for some utilities which otherwise would not compile.
default errorDocRequirements :: ErrorRequirements e => Dict (ErrorRequirements e) Source #
Instances
typeDocMdDescriptionReferToError :: forall e. IsError e => Markdown Source #
Implementation of typeDocMdDescription
(of TypeHasDoc
typeclass)
for Haskell types which sole purpose is to be error.
isInternalErrorClass :: ErrorClass -> Bool Source #
Whether given error class is about internal errors.
Internal errors are not enlisted on per-entrypoint basis, only once for the entire contract.
data UnspecifiedError Source #
Use this type as replacement for ()
when you really want to leave
error cause unspecified.
Instances
data Impossible (reason :: Symbol) Source #
Use this error when sure that failing at the current position is possible in no curcumstances (including invalid user input or misconfigured storage).
To use this as error, you have to briefly specify the reason why the error scenario is impossible (experimental feature).
Instances
KnownSymbol reason => ErrorHasDoc (Impossible reason) Source # | |
Defined in Lorentz.Errors type ErrorRequirements (Impossible reason) Source # errorDocName :: Text Source # errorDocMdCause :: Markdown Source # errorDocMdCauseInEntrypoint :: Markdown Source # errorDocHaskellRep :: Markdown Source # errorDocClass :: ErrorClass Source # errorDocDependencies :: [SomeDocDefinitionItem] Source # errorDocRequirements :: Dict (ErrorRequirements (Impossible reason)) Source # | |
KnownSymbol reason => IsError (Impossible reason) Source # | |
Defined in Lorentz.Errors errorToVal :: Impossible reason -> (forall (t :: T). ErrorScope t => Value t -> r) -> r Source # errorFromVal :: forall (t :: T). SingI t => Value t -> Either Text (Impossible reason) Source # failUsing :: forall (s :: [Type]) (t :: [Type]). IsError (Impossible reason) => Impossible reason -> s :-> t Source # | |
type ErrorRequirements (Impossible reason) Source # | |
Defined in Lorentz.Errors |
Type wrapper for an IsError
.
General instructions
failUnexpected :: MText -> s :-> t Source #
Fail, providing a reference to the place in the code where this function is called.
Like error
in Haskell code, this instruction is for internal errors only.
Custom errors
data NoErrorArg Source #
To be used as ErrorArg
instance when failing with just
a string
instead of pair string x
data UnitErrorArg Source #
To be used as ErrorArg
instances. This is equivalent to using
()
but using UnitErrorArg
is preferred since ()
behavior could
be changed in the future.
type family ErrorArg (tag :: Symbol) :: Type Source #
Declares a custom error, defining error name - error argument
relation.
If your error is supposed to carry no argument, then provide ()
.
Note that this relation is defined globally rather than on per-contract basis, so define errors accordingly. If your error has argument specific to your contract, call it such that error name reflects its belonging to this contract.
This is the basic [error format].
Instances
type ErrorArg "emptySupplied" Source # | Someone constructed |
Defined in Lorentz.Empty | |
type ErrorArg "nOT_SINGLE_TICKET_TOKEN" Source # | |
Defined in Lorentz.Tickets | |
type ErrorArg "nOT_TICKET_TARGET" Source # | |
Defined in Lorentz.Tickets | |
type ErrorArg "no_view" Source # | |
Defined in Lorentz.Macro | |
type ErrorArg "uparamArgumentUnpackFailed" Source # | |
Defined in Lorentz.UParam | |
type ErrorArg "uparamNoSuchEntrypoint" Source # | |
Defined in Lorentz.UParam | |
type ErrorArg "wRONG_TICKETER" Source # | |
Defined in Lorentz.Tickets |
data CustomError (tag :: Symbol) Source #
Material custom error.
Use this in pattern matches against error (e.g. in tests).
CustomError | |
|
Instances
type CustomErrorRep tag = CustomErrorArgRep (ErrorArg tag) Source #
How CustomError
is actually represented in Michelson.
class IsCustomErrorArgRep a where Source #
Typeclass implements various method that work with CustomErrorArgRep
.
verifyErrorTag :: MText -> a -> Either Text a Source #
customErrorRepDocDeps :: [SomeDocDefinitionItem] Source #
customErrorHaskellRep :: (KnownSymbol tag, CustomErrorHasDoc tag) => Proxy tag -> Markdown Source #
Instances
IsCustomErrorArgRep MText Source # | |
Defined in Lorentz.Errors verifyErrorTag :: MText -> MText -> Either Text MText Source # customErrorRepDocDeps :: [SomeDocDefinitionItem] Source # customErrorHaskellRep :: forall (tag :: Symbol). (KnownSymbol tag, CustomErrorHasDoc tag) => Proxy tag -> Markdown Source # | |
TypeHasDoc errArg => IsCustomErrorArgRep (MText, errArg) Source # | |
Defined in Lorentz.Errors verifyErrorTag :: MText -> (MText, errArg) -> Either Text (MText, errArg) Source # customErrorRepDocDeps :: [SomeDocDefinitionItem] Source # customErrorHaskellRep :: forall (tag :: Symbol). (KnownSymbol tag, CustomErrorHasDoc tag) => Proxy tag -> Markdown Source # |
type MustHaveErrorArg errorTag expectedArgRep = (AssertTypesEqual (CustomErrorRep errorTag) expectedArgRep ((('Text "Error argument type is " :<>: 'ShowType expectedArgRep) :<>: 'Text " but given error requires argument of type ") :<>: 'ShowType (CustomErrorRep errorTag)), CustomErrorRep errorTag ~ expectedArgRep) Source #
failCustom :: forall tag err s any. (MustHaveErrorArg tag (MText, err), CustomErrorHasDoc tag, KnownError err) => Label tag -> (err ': s) :-> any Source #
Fail with given custom error.
failCustom_ :: forall tag s any. (MustHaveErrorArg tag (MText, ()), CustomErrorHasDoc tag) => Label tag -> s :-> any Source #
Specialization of failCustom
for unit-arg errors.
failCustomNoArg :: forall tag s any. (MustHaveErrorArg tag MText, CustomErrorHasDoc tag) => Label tag -> s :-> any Source #
Fail with given custom error.
Documentation
data ErrorClass Source #
Error class on how the error should be handled by the client.
ErrClassActionException | Normal expected error. Examples: "insufficient balance", "wallet does not exist". |
ErrClassBadArgument | Invalid argument passed to entrypoint.
Examples: your entrypoint accepts an enum represented as |
ErrClassContractInternal | Unexpected error. Most likely it means that there is a bug in the contract or the contract has been deployed incorrectly. |
ErrClassUnknown | It's possible to leave error class unspecified. |
Instances
Read ErrorClass Source # | |
Defined in Lorentz.Errors readsPrec :: Int -> ReadS ErrorClass # readList :: ReadS [ErrorClass] # readPrec :: ReadPrec ErrorClass # readListPrec :: ReadPrec [ErrorClass] # | |
Buildable ErrorClass Source # | |
Defined in Lorentz.Errors build :: ErrorClass -> Builder # | |
Lift ErrorClass Source # | |
Defined in Lorentz.Errors lift :: ErrorClass -> Q Exp # liftTyped :: ErrorClass -> Q (TExp ErrorClass) # |
class (KnownSymbol tag, TypeHasDoc (CustomErrorRep tag), IsError (CustomError tag)) => CustomErrorHasDoc tag where Source #
customErrDocMdCause :: Markdown Source #
What should happen for this error to be raised.
customErrDocMdCauseInEntrypoint :: Markdown Source #
Brief version of customErrDocMdCause
.
This will appear along with the error when mentioned in entrypoint description.
By default, the first sentence of the full description is used.
customErrClass :: ErrorClass Source #
Error class.
By default this returns "unknown error" class; though you should provide explicit implementation in order to avoid a warning.
customErrArgumentSemantics :: Maybe Markdown Source #
Clarification of error argument meaning.
Provide when it's not obvious, e.g. argument is not named with :!
.
NOTE: This should not be an entire sentence, rather just the semantic backbone.
Bad:
* Error argument stands for the previous value of approval.
Good:
* the previous value of approval
* pair, first argument of which is one thing, and the second is another
Instances
CustomErrorHasDoc "emptySupplied" Source # | |
CustomErrorHasDoc "nOT_SINGLE_TICKET_TOKEN" Source # | |
CustomErrorHasDoc "nOT_TICKET_TARGET" Source # | |
CustomErrorHasDoc "no_view" Source # | |
CustomErrorHasDoc "uparamArgumentUnpackFailed" Source # | |
CustomErrorHasDoc "uparamNoSuchEntrypoint" Source # | |
CustomErrorHasDoc "wRONG_TICKETER" Source # | |
Mentions that contract uses given error.
DError :: ErrorHasDoc e => Proxy e -> DError |
Instances
Eq DError Source # | |
Ord DError Source # | |
DocItem DError Source # | |
Defined in Lorentz.Errors type DocItemPlacement DError :: DocItemPlacementKind # type DocItemReferenced DError :: DocItemReferencedKind # docItemPos :: Natural # docItemSectionName :: Maybe Text # docItemSectionDescription :: Maybe Markdown # docItemSectionNameStyle :: DocSectionNameStyle # docItemRef :: DError -> DocItemRef (DocItemPlacement DError) (DocItemReferenced DError) # docItemToMarkdown :: HeaderLevel -> DError -> Markdown # docItemToToc :: HeaderLevel -> DError -> Markdown # docItemDependencies :: DError -> [SomeDocDefinitionItem] # docItemsOrder :: [DError] -> [DError] # | |
type DocItemPlacement DError Source # | |
Defined in Lorentz.Errors | |
type DocItemReferenced DError Source # | |
Defined in Lorentz.Errors |
Documentation for custom errors.
Mentions that entrypoint throws given error.
DThrows :: ErrorHasDoc e => Proxy e -> DThrows |
Instances
Eq DThrows Source # | |
DocItem DThrows Source # | |
Defined in Lorentz.Errors type DocItemPlacement DThrows :: DocItemPlacementKind # type DocItemReferenced DThrows :: DocItemReferencedKind # docItemPos :: Natural # docItemSectionName :: Maybe Text # docItemSectionDescription :: Maybe Markdown # docItemSectionNameStyle :: DocSectionNameStyle # docItemRef :: DThrows -> DocItemRef (DocItemPlacement DThrows) (DocItemReferenced DThrows) # docItemToMarkdown :: HeaderLevel -> DThrows -> Markdown # docItemToToc :: HeaderLevel -> DThrows -> Markdown # docItemDependencies :: DThrows -> [SomeDocDefinitionItem] # docItemsOrder :: [DThrows] -> [DThrows] # | |
type DocItemPlacement DThrows Source # | |
Defined in Lorentz.Errors | |
type DocItemReferenced DThrows Source # | |
Defined in Lorentz.Errors |
Internals
errorTagToText :: forall tag. KnownSymbol tag => Text Source #
errorTagToMText :: Label tag -> MText Source #
Demote error tag to term level.