Skip to content

Commit

Permalink
Merge pull request #741 from yesodweb/persistentErrorMessages
Browse files Browse the repository at this point in the history
More verbose error messages when failing to parse database results in…
  • Loading branch information
MaxGabriel committed Jan 17, 2018
2 parents 57f2b96 + 36dffb5 commit 453ef08
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 46 deletions.
4 changes: 4 additions & 0 deletions persistent-template/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.5.3.1

* Slight improvement to the error message when a Persistent field can't be parsed from database results

## 2.5.3

* Exposed `parseReferences` to allow custom QuasiQuoters
Expand Down
2 changes: 1 addition & 1 deletion persistent-template/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ mapLeft _ (Right r) = Right r
mapLeft f (Left l) = Left (f l)

fieldError :: Text -> Text -> Text
fieldError fieldName err = "field " `mappend` fieldName `mappend` ": " `mappend` err
fieldError fieldName err = "Couldn't parse field `" `mappend` fieldName `mappend` "` from database results: " `mappend` err

mkFromPersistValues :: MkPersistSettings -> EntityDef -> Q [Clause]
mkFromPersistValues _ t@(EntityDef { entitySum = False }) =
Expand Down
2 changes: 1 addition & 1 deletion persistent-template/persistent-template.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent-template
version: 2.5.3
version: 2.5.3.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down
5 changes: 5 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.7.3.1

* Improve error messages when failing to parse database results into Persistent records.
* A handful of `fromPersistField` implementations called `error` instead of returning a `Left Text`. All of the implementations were changed to return `Left`.

## 2.7.3

* Reverts [#723](https://github.com/yesodweb/persistent/pull/723), which generalized functions using the `BackendCompatible` class. These changes were an accidental breaking change.
Expand Down
141 changes: 99 additions & 42 deletions persistent/Database/Persist/Class/PersistField.hs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion persistent/Database/Persist/Sql/Orphan/PersistStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ instance PersistStoreRead SqlBackend where
Nothing -> return Nothing
Just vals ->
case fromPersistValues $ if noColumns then [] else vals of
Left e -> error $ "get " ++ show k ++ ": " ++ unpack e
Left e -> error $ "Error when calling `get` with key: " ++ show k ++ ". Failed to create `" ++ (unpack (unHaskellName $ entityHaskell t)) ++ "` because of error: " ++ unpack e ++ " Potential solution: If your field is using a custom PersistField instance, check that it's correct."
Right v -> return $ Just v
instance PersistStoreRead SqlReadBackend where
get k = withReaderT persistBackend $ get k
Expand Down
2 changes: 1 addition & 1 deletion persistent/persistent.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent
version: 2.7.3
version: 2.7.3.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
Expand Down

0 comments on commit 453ef08

Please sign in to comment.