Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/KDL/Decoder/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ module KDL.Decoder.Arrow (

-- * Decoder
Decoder,
module KDL.Decoder.Internal.DecodeM,
liftDecodeM,
fail,
withDecoder,
debug,

-- ** DecodeM
DecodeM,
runDecodeM,
decodeThrow,
failM,

-- ** Decode errors
module KDL.Decoder.Internal.Error,

-- * Document
DocumentDecoder (..),
document,
Expand Down Expand Up @@ -112,6 +121,7 @@ import Data.Word (Word16, Word32, Word64, Word8)
import GHC.Int (Int16, Int32, Int8)
import KDL.Decoder.Internal.DecodeM
import KDL.Decoder.Internal.Decoder
import KDL.Decoder.Internal.Error
import KDL.Decoder.Schema (
Schema (..),
SchemaItem (..),
Expand Down
2 changes: 1 addition & 1 deletion src/KDL/Decoder/Internal/DecodeM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ runDecodeM (DecodeM f) = f Left Left Right
--
-- This error is non-fatal and can be handled by '<|>'. See 'makeFatal'
-- for more information.
decodeThrow :: BaseDecodeError -> DecodeM a
decodeThrow :: DecodeErrorKind -> DecodeM a
decodeThrow e = DecodeM $ \_ onFail _ -> onFail $ DecodeError Nothing [([], e)]

-- | Throw a 'DecodeError_Custom' error.
Expand Down
8 changes: 5 additions & 3 deletions src/KDL/Decoder/Internal/Error.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

module KDL.Decoder.Internal.Error (
DecodeError (..),
BaseDecodeError (..),
BaseDecodeError,
DecodeErrorKind (..),
Context,
ContextItem (..),
renderDecodeError,
Expand All @@ -28,14 +29,15 @@ import KDL.Types (

data DecodeError = DecodeError
{ filepath :: Maybe FilePath
, errors :: [(Context, BaseDecodeError)]
, errors :: [BaseDecodeError]
}
deriving (Show, Eq)
instance Semigroup DecodeError where
DecodeError fp1 e1 <> DecodeError fp2 e2 = DecodeError (fp1 <|> fp2) (e1 <> e2)
instance Monoid DecodeError where
mempty = DecodeError Nothing []

type BaseDecodeError = (Context, DecodeErrorKind)
type Context = [ContextItem]

data ContextItem
Expand All @@ -51,7 +53,7 @@ data ContextItem
}
deriving (Show, Eq, Ord)

data BaseDecodeError
data DecodeErrorKind
= DecodeError_Custom Text
| DecodeError_ParseError Text
| DecodeError_ExpectedNode {name :: Text, index :: Int}
Expand Down
Loading