Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)