Skip to content

Commit

Permalink
Better aeson error messages. addresses #269
Browse files Browse the repository at this point in the history
This overrides the aeson combinators to have better error messages
Just import Data.Aeson.Extended instead of Data.Aeson
  • Loading branch information
gregwebs committed Jun 11, 2015
1 parent 3b32872 commit b640602
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 15 deletions.
23 changes: 23 additions & 0 deletions src/Data/Aeson/Extended.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- | The purpose of this module is to provide better failure messages
-- When parsing a key of an object, this makes sure the key itself will show up
module Data.Aeson.Extended (
module Export
, (.:)
, (.:?)
) where

import Data.Aeson as Export hiding ((.:), (.:?))
import qualified Data.Aeson as A

import Data.Aeson.Types hiding ((.:), (.:?))

import Data.Text (unpack, Text)
import Data.Monoid ((<>))

(.:) :: FromJSON a => Object -> Text -> Parser a
(.:) o p = modifyFailure (("failed to parse field " <> unpack p <> ": ") <>) (o A..: p)
{-# INLINE (.:) #-}

(.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
(.:?) o p = modifyFailure (("failed to parse field " <> unpack p <> ": ") <>) (o A..:? p)
{-# INLINE (.:?) #-}
2 changes: 1 addition & 1 deletion src/Network/HTTP/Download.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Monad.Catch (MonadThrow, throwM)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Reader (MonadReader, ReaderT, ask,
runReaderT)
import Data.Aeson (FromJSON, parseJSON)
import Data.Aeson.Extended (FromJSON, parseJSON)
import Data.Aeson.Parser (json')
import Data.Aeson.Types (parseEither)
import qualified Data.ByteString as S
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Build/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Stack.Build.Types where

import Control.DeepSeq
import Control.Exception
import Data.Aeson
import Data.Aeson.Extended
import Data.Binary (Binary(..))
import qualified Data.ByteString as S
import Data.Char (isSpace)
Expand Down
3 changes: 1 addition & 2 deletions src/Stack/BuildPlan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ import Control.Monad.Reader (asks)
import Control.Monad.State.Strict (State, execState, get, modify,
put)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Aeson (FromJSON (..))
import Data.Aeson (withObject, withText, (.:))
import Data.Aeson.Extended (FromJSON (..), withObject, withText, (.:))
import Data.Binary.VersionTagged (taggedDecodeOrLoad)
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as S8
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Control.Monad.Logger hiding (Loc)
import Control.Monad.Reader (MonadReader, ask, runReaderT)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Crypto.Hash.SHA256 as SHA256
import Data.Aeson
import Data.Aeson.Extended
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Lazy as L
import Data.Either (partitionEithers)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Control.Monad.Catch (MonadThrow, throwM)
import Control.Monad.IO.Class (MonadIO,liftIO)
import Control.Monad.Logger (MonadLogger,logError,logInfo,logWarn)
import Control.Monad.Writer (execWriter,runWriter,tell)
import Data.Aeson (FromJSON(..),(.:),(.:?),(.!=),eitherDecode)
import Data.Aeson.Extended (FromJSON(..),(.:),(.:?),(.!=),eitherDecode)
import Data.ByteString.Builder (stringUtf8,charUtf8,toLazyByteString)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as LBS
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/PackageIndex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Control.Monad.Logger (MonadLogger, logDebug,
logInfo, logWarn)
import Control.Monad.Reader (asks)

import Data.Aeson
import Data.Aeson.Extended
import qualified Data.Binary as Binary
import Data.Binary.VersionTagged (taggedDecodeOrLoad)
import Data.ByteString (ByteString)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Control.Monad.Reader (MonadReader, ReaderT (..), asks)
import Control.Monad.State (get, put, modify)
import Control.Monad.Trans.Control

import Data.Aeson
import Data.Aeson.Extended
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import Data.Conduit (Conduit, ($$), (=$), await, yield, awaitForever)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Control.Exception
import Control.Monad (liftM, mzero)
import Control.Monad.Catch (MonadThrow, throwM)
import Control.Monad.Reader (MonadReader, ask, asks, MonadIO, liftIO)
import Data.Aeson (ToJSON, toJSON, FromJSON, parseJSON, withText, withObject, object
import Data.Aeson.Extended (ToJSON, toJSON, FromJSON, parseJSON, withText, withObject, object
,(.=), (.:?), (.!=), (.:), Value (String))
import Data.Binary (Binary)
import Data.ByteString (ByteString)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/Docker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Stack.Types.Docker where

import Control.Applicative
import Data.Aeson
import Data.Aeson.Extended
import Data.Monoid
import Data.Text (Text)
import Path
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/FlagName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Stack.Types.FlagName

import Control.Applicative
import Control.Monad.Catch
import Data.Aeson
import Data.Aeson.Extended
import Data.Attoparsec.ByteString.Char8
import Data.Attoparsec.Combinators
import Data.Binary (Binary)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/GhcPkgId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Stack.Types.GhcPkgId

import Control.Applicative
import Control.Monad.Catch
import Data.Aeson
import Data.Aeson.Extended
import Data.Attoparsec.ByteString.Char8
import Data.Binary (Binary)
import Data.ByteString.Char8 (ByteString)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/PackageIdentifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Control.Applicative
import Control.DeepSeq
import Control.Exception (Exception)
import Control.Monad.Catch (MonadThrow, throwM)
import Data.Aeson
import Data.Aeson.Extended
import Data.Attoparsec.ByteString.Char8
import Data.Binary (Binary)
import Data.ByteString (ByteString)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/PackageName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Control.Applicative
import Control.DeepSeq
import Control.Monad
import Control.Monad.Catch
import Data.Aeson
import Data.Aeson.Extended
import Data.Attoparsec.ByteString.Char8
import Data.Attoparsec.Combinators
import Data.Binary (Binary)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Types/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Stack.Types.Version
import Control.Applicative
import Control.DeepSeq
import Control.Monad.Catch
import Data.Aeson
import Data.Aeson.Extended
import Data.Attoparsec.ByteString.Char8
import Data.Binary (Binary)
import Data.ByteString (ByteString)
Expand Down
1 change: 1 addition & 0 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library
Path.IO
System.Process.PagerEditor
Paths_stack
Data.Aeson.Extended
Data.Attoparsec.Combinators
Data.Binary.VersionTagged
Data.Set.Monad
Expand Down

0 comments on commit b640602

Please sign in to comment.