Skip to content

Commit ff16eb6

Browse files
authored
Merge pull request #2762 from IntersectMBO/test
chore(#2757): add exception handle on voting power query execution
2 parents ea92600 + 5b3620b commit ff16eb6

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ changes.
1212

1313
### Added
1414

15-
-
15+
- Add exception handler on stake key voting power query execution [Issue 2757](https://github.com/IntersectMBO/govtool/issues/2757)
1616

1717
### Fixed
1818

govtool/backend/src/VVA/AdaHolder.hs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
{-# LANGUAGE FlexibleContexts #-}
2-
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TemplateHaskell #-}
4-
{-# LANGUAGE TypeApplications #-}
1+
{-# LANGUAGE FlexibleContexts #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE TemplateHaskell #-}
4+
{-# LANGUAGE TypeApplications #-}
5+
{-# LANGUAGE ScopedTypeVariables #-}
56

67
module VVA.AdaHolder where
78

9+
import Control.Exception (try, SomeException)
810
import Control.Monad.Except
911
import Control.Monad.Reader
1012

@@ -51,9 +53,11 @@ getStakeKeyVotingPower ::
5153
Text ->
5254
m Integer
5355
getStakeKeyVotingPower stakeKey = withPool $ \conn -> do
54-
result <- liftIO $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
55-
case result of
56-
[(votingPower,_)] -> return $ floor votingPower
57-
_ -> do
58-
liftIO $ Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey)
59-
return 0
56+
liftIO $ do
57+
result <- try $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
58+
case result of
59+
Left (e :: SomeException) -> do
60+
Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey)
61+
return 0
62+
Right [(votingPower,_)] -> return $ floor votingPower
63+
_ -> error ("multiple voting power entries for stake key: " <> unpack stakeKey)

0 commit comments

Comments
 (0)