Exception type used in most Lean monads
- error
(ref : Lean.Syntax)
(msg : Lean.MessageData)
: Lean.Exception
Error messages that are displayed to users.
ref
is used to provide position information. - internal
(id : Lean.InternalExceptionId)
(extra : Lean.KVMap := { entries := [] })
: Lean.Exception
Internal exceptions that are not meant to be seen by users. Examples: "postpone elaboration", "stuck at universe constraint", etc.
Instances For
Convert exception into a structured message.
Equations
- (Lean.Exception.error ref msg).toMessageData = msg
- (Lean.Exception.internal id extra).toMessageData = (Lean.MessageData.ofFormat ∘ Lean.format) id.toString
Instances For
Equations
- (Lean.Exception.error ref msg).hasSyntheticSorry = msg.hasSyntheticSorry
- x✝.hasSyntheticSorry = false
Instances For
Return syntax object providing position information for the exception. Recall that internal exceptions do not have position information.
Equations
- (Lean.Exception.error ref msg).getRef = ref
- (Lean.Exception.internal id extra).getRef = Lean.Syntax.missing
Instances For
Equations
- Lean.instInhabitedException = { default := Lean.Exception.error default default }
Similar to AddMessageContext
, but for error messages.
The default instance just uses AddMessageContext
.
In error messages, we may want to provide additional information (e.g., macro expansion stack),
and refine the (ref : Syntax)
.
- add : Lean.Syntax → Lean.MessageData → m (Lean.Syntax × Lean.MessageData)
Instances
Equations
- Lean.instAddErrorMessageContextOfAddMessageContextOfMonad m = { add := fun (ref : Lean.Syntax) (msg : Lean.MessageData) => do let msg ← Lean.addMessageContext msg pure (ref, msg) }
- getRef : m Lean.Syntax
- add : Lean.Syntax → Lean.MessageData → m (Lean.Syntax × Lean.MessageData)
Instances
Throw an error exception using the given message data.
The result of getRef
is used as position information.
Recall that getRef
returns the current "reference" syntax.
Equations
- Lean.throwError msg = do let ref ← Lean.getRef let __discr ← Lean.AddErrorMessageContext.add ref msg match __discr with | (ref, msg) => throw (Lean.Exception.error ref msg)
Instances For
Throw an unknown constant error message.
Equations
- Lean.throwUnknownConstant constName = Lean.throwError (Lean.toMessageData "unknown constant '" ++ Lean.toMessageData (Lean.MessageData.ofConstName constName) ++ Lean.toMessageData "'")
Instances For
Throw an error exception using the given message data and reference syntax.
Equations
- Lean.throwErrorAt ref msg = Lean.withRef ref (Lean.throwError msg)
Instances For
Convert an Except
into a m
monadic action, where m
is any monad that
implements MonadError
.
Equations
Instances For
Throw an error exception for the given kernel exception.
Equations
- Lean.throwKernelException ex = do let __do_lift ← Lean.getOptions Lean.throwError (ex.toMessageData __do_lift)
Instances For
Lift from Except KernelException
to m
when m
can throw kernel exceptions.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.instMonadRecDepthStateRefT'OfMonad = inferInstanceAs (Lean.MonadRecDepth (ReaderT (ST.Ref ω σ) m))
Equations
- Lean.instMonadRecDepthMonadCacheTOfMonad = inferInstanceAs (Lean.MonadRecDepth (StateRefT' ω (Std.HashMap α β) m))
Throw a "maximum recursion depth has been reached" exception using the given reference syntax.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return true if ex
was generated by throwMaxRecDepthAt
.
This function is a bit hackish. The max rec depth exception should probably be an internal exception,
but it is also produced by MacroM
which implemented in the prelude, and internal exceptions have not
been defined yet.
Equations
- (Lean.Exception.error ref (Lean.MessageData.tagged `runtime.maxRecDepth a)).isMaxRecDepth = true
- ex.isMaxRecDepth = false
Instances For
Increment the current recursion depth and then execute x
.
Throw an exception if maximum recursion depth has been reached.
We use this combinator to prevent stack overflows.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Macro for throwing error exceptions. The argument can be an interpolated string.
It is a convenient way of building MessageData
objects.
The result of getRef
is used as position information.
Recall that getRef
returns the current "reference" syntax.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Macro for throwing error exceptions. The argument can be an interpolated string.
It is a convenient way of building MessageData
objects.
The first argument must be a Syntax
that provides position information for
the error message.
throwErrorAt ref msg
is equivalent to withRef ref <| throwError msg
Equations
- One or more equations did not get rendered due to their size.