| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
KDL.Decoder.Internal.DecodeM
Contents
Synopsis
- module KDL.Decoder.Internal.Error
- data DecodeM a
- runDecodeM :: DecodeM a -> Either DecodeError a
- decodeThrow :: DecodeErrorKind -> DecodeM a
- failM :: Text -> DecodeM a
- addContext :: ContextItem -> DecodeM a -> DecodeM a
Decoding errors
module KDL.Decoder.Internal.Error
DecodeM monad
The monad that returns either a DecodeError or a result of type a.
The odd structure here is because of our backtracking semantics. We want to collect all errors that may appear (even if a value is successfully parsed) so that if we get a failure later on, we can return the deepest error, even if it was in a successful branch.
Take this motivating example: a node takes an arbitrary number of string args. If you pass some strings then a number, it'll successfully parse up to the number and return success, only for the node to fail later with "unexpected argument: 123". But the true error was "unexpected number, expected string".
Constructors
| DecodeM_Found a [BaseDecodeError] | |
| DecodeM_Fail (NonEmpty BaseDecodeError) |
runDecodeM :: DecodeM a -> Either DecodeError a Source #
Run a DecodeM action and return the result or the deepest error found.
decodeThrow :: DecodeErrorKind -> DecodeM a Source #
Throw an error.
addContext :: ContextItem -> DecodeM a -> DecodeM a Source #
Add context to all errors that occur in the given action.