Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(#2757): add exception handle on voting power query execution #2762

Merged
merged 3 commits into from
Jan 27, 2025
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)
Loading