Skip to content

Commit

Permalink
refactor(eo-phi-normalizer): use throwIO instead of throw
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Dec 4, 2024
1 parent 20d64a0 commit fba4c22
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

module Main (main) where

import Control.Exception (Exception (..), SomeException, catch, throw)
import Control.Exception (Exception (..), SomeException, catch, throwIO)
import Control.Lens.Lens ((&))
import Control.Lens.Operators ((?~))
import Control.Monad (forM, unless, when)
Expand Down Expand Up @@ -466,14 +466,14 @@ getFile = \case
Just file' ->
doesFileExist file' >>= \case
True -> pure (Just file')
False -> throw $ FileDoesNotExist file'
False -> throwIO $ FileDoesNotExist file'

getProgram :: Maybe FilePath -> IO Program
getProgram inputFile = do
inputFile' <- getFile inputFile
src <- maybe getContents' readFile inputFile' `catch` (throw . CouldNotRead . show @SomeException)
src <- maybe getContents' readFile inputFile' `catch` (throwIO . CouldNotRead . show @SomeException)
case parseProgram src of
Left err -> throw $ CouldNotParse err
Left err -> throwIO $ CouldNotParse err
Right program -> pure program

getLoggers :: Maybe FilePath -> IO (String -> IO (), String -> IO ())
Expand Down Expand Up @@ -510,7 +510,7 @@ getMetrics' program bindingsPath = do
getMetrics :: Maybe String -> Maybe FilePath -> IO ProgramMetrics
getMetrics bindingsPath inputFile = do
program <- getProgram inputFile
either throw pure (getMetrics' program bindingsPath)
either throwIO pure (getMetrics' program bindingsPath)

injectLamdbaPackage :: [Binding] -> [Binding]
injectLamdbaPackage bs
Expand Down Expand Up @@ -596,7 +596,7 @@ main = (withCP65001 . withUtf8) do
return (False, ruleSet.title, convertRuleNamed <$> ruleSet.rules)
unless (single || json || (chain && latex)) $ logStrLn ruleSetTitle
bindingsWithDeps <- case deepMergePrograms (program' : deps) of
Left err -> throw (CouldNotMergeDependencies err)
Left err -> throwIO (CouldNotMergeDependencies err)
Right (Program bindingsWithDeps) -> return bindingsWithDeps
let Program bindings = program'
uniqueResults
Expand All @@ -608,7 +608,7 @@ main = (withCP65001 . withUtf8) do
limits = ApplicationLimits maxDepth (maxGrowthFactor * objectSize (Formation bindings))
ctx = (defaultContext rules (Formation bindingsWithDeps)){builtinRules = builtin} -- IMPORTANT: context contains dependencies!
totalResults = length uniqueResults
when (null uniqueResults || null (head uniqueResults)) (throw CouldNotNormalize)
when (null uniqueResults || null (head uniqueResults)) (throwIO CouldNotNormalize)
if
| single && json ->
logStrLn
Expand Down Expand Up @@ -663,7 +663,7 @@ main = (withCP65001 . withUtf8) do
program' <- getProgram inputFile
deps <- mapM (getProgram . Just) dependencies
bindingsWithDeps <- case deepMergePrograms (program' : deps) of
Left err -> throw (CouldNotMergeDependencies err)
Left err -> throwIO (CouldNotMergeDependencies err)
Right (Program bindingsWithDeps) -> return bindingsWithDeps
(builtin, _ruleSetTitle, rules) <-
case rulesPath of
Expand Down

0 comments on commit fba4c22

Please sign in to comment.