Skip to content

Add escape-hatch custom error constructor #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/Data/Argonaut/Decode/Error.purs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- | Originally implemented in:
-- | Originally implemented in:
-- | https://github.com/garyb/purescript-codec-argonaut
module Data.Argonaut.Decode.Error where

Expand All @@ -15,6 +15,7 @@ data JsonDecodeError
| AtKey String JsonDecodeError
| Named String JsonDecodeError
| MissingValue
| CustomError String

derive instance eqJsonDecodeError :: Eq JsonDecodeError
derive instance ordJsonDecodeError :: Ord JsonDecodeError
Expand All @@ -28,6 +29,7 @@ instance showJsonDecodeError :: Show JsonDecodeError where
AtKey k e -> "(AtKey " <> show k <> " " <> show e <> ")"
Named s e -> "(Named " <> show s <> " " <> show e <> ")"
MissingValue -> "MissingValue"
CustomError e -> "(CustomError " <> e <> ")"

-- | Prints a `JsonDecodeError` as a readable error message.
printJsonDecodeError :: JsonDecodeError -> String
Expand All @@ -41,3 +43,4 @@ printJsonDecodeError err =
AtKey key inner -> " At object key \'" <> key <> "\':\n" <> go inner
Named name inner -> " Under '" <> name <> "':\n" <> go inner
MissingValue -> " No value was found."
CustomError e -> " " <> e