Skip to content

Commit

Permalink
Add convenience withStringErrors function
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-the-slime committed Nov 6, 2023
1 parent 51737ae commit 6b9bb4a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Yoga/JSON/Error.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ module Yoga.JSON.Error where
import Prelude

import Foreign (ForeignError(..))
import Data.Semigroup.Foldable (intercalateMap)
import Data.Bifunctor (lmap)
import Yoga.JSON (E)
import Data.Either (Either)

toJSONPath ForeignError String
toJSONPath fe = "$" <> path
Expand All @@ -20,6 +24,9 @@ renderHumanError = errorToJSON >>> toHuman
where
toHuman { message, path } = message <> " at " <> path

withStringErrors :: forall a. E a -> Either String a
withStringErrors = lmap (intercalateMap "\n" renderHumanError)

errorToJSON
ForeignError
{ message String
Expand Down

0 comments on commit 6b9bb4a

Please sign in to comment.