Skip to content

Commit

Permalink
Merge pull request #2762 from IntersectMBO/test
Browse files Browse the repository at this point in the history
chore(#2757): add exception handle on voting power query execution
  • Loading branch information
MSzalowski authored Jan 27, 2025
2 parents ea92600 + 5b3620b commit ff16eb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ changes.

### Added

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

### Fixed

Expand Down
24 changes: 14 additions & 10 deletions govtool/backend/src/VVA/AdaHolder.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}

module VVA.AdaHolder where

import Control.Exception (try, SomeException)
import Control.Monad.Except
import Control.Monad.Reader

Expand Down Expand Up @@ -51,9 +53,11 @@ getStakeKeyVotingPower ::
Text ->
m Integer
getStakeKeyVotingPower stakeKey = withPool $ \conn -> do
result <- liftIO $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
case result of
[(votingPower,_)] -> return $ floor votingPower
_ -> do
liftIO $ Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey)
return 0
liftIO $ do
result <- try $ SQL.query @_ @(Scientific, ByteString) conn getVotingPowerSql (SQL.Only stakeKey)
case result of
Left (e :: SomeException) -> do
Text.putStrLn ("couldn't fetch voting power for stake key: " <> stakeKey)
return 0
Right [(votingPower,_)] -> return $ floor votingPower
_ -> error ("multiple voting power entries for stake key: " <> unpack stakeKey)

0 comments on commit ff16eb6

Please sign in to comment.