Skip to content

Commit

Permalink
Merge pull request #57 from biocad/maksbotan/TH-better-errors
Browse files Browse the repository at this point in the history
Better error message in TH converter, unpack Int as Double
  • Loading branch information
maksbotan committed Sep 28, 2023
2 parents c12b491 + 3aef2c1 commit de6e582
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.0.3.1] - 2023-09-28
### Changed
- `FromValue` now can unpack DB `Int` as Haskell `Double`.
- Verbose error in TemplateHaskell converter when property of a node or a relationship can't be
unpacked.

## [0.0.3.0] - 2023-08-17
### Added
- `IsString` instance for `Cond` and `Conds`.
Expand Down
2 changes: 1 addition & 1 deletion hasbolt-extras.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: hasbolt-extras
version: 0.0.3.0
version: 0.0.3.1
synopsis: Extras for hasbolt library
description: Extras for hasbolt library
homepage: https://github.com/biocad/hasbolt-extras#readme
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Bolt/Extras/Internal/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Database.Bolt.Extras.Internal.Types (FromValue (..), NodeLike (
NodeLikeProps (..), ToIsValue (..),
ToValue (..))
import Database.Bolt.Extras.Utils (currentLoc)
import GHC.Float (double2Float, float2Double)
import GHC.Float (double2Float, float2Double, int2Double)
import GHC.Stack (HasCallStack)


Expand Down Expand Up @@ -80,6 +80,7 @@ instance FromValue Int where

instance FromValue Double where
fromValue (F doubleV) = doubleV
fromValue (I intV) = int2Double intV
fromValue v = error $ $currentLoc ++ "could not unpack " ++ show v ++ " into Double"

instance FromValue Float where
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Bolt/Extras/Template/Internal/Converters.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ getProp container (fieldName, fieldMaybe) | fieldMaybe && fieldName `notMember`
where
exactE v = case exactEither v of
Right res -> res
Left err -> error $ show err
Left err -> error
$ "Could not unpack "
<> unpack fieldName <> ": " <> show err
<> ", value: " <> show v

unpackError :: HasCallStack => Show c => c -> String -> a
unpackError container label = error $ $currentLoc ++ " could not unpack " ++ label ++ " from " ++ show container
Expand Down

0 comments on commit de6e582

Please sign in to comment.