Skip to content

Commit dc6867a

Browse files
committed
Clean-up: factor out handlers in kore-repl
1 parent 6865dc9 commit dc6867a

File tree

2 files changed

+38
-49
lines changed

2 files changed

+38
-49
lines changed

kore/app/repl/Main.hs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ module Main (main) where
66

77
import Control.Concurrent.MVar
88
import Control.Monad.Catch
9-
( SomeException
10-
, fromException
11-
, handle
12-
, throwM
9+
( handle
1310
)
1411
import Data.Reflection
1512
import GlobalMain
@@ -22,30 +19,25 @@ import qualified Kore.IndexedModule.MetadataToolsBuilder as MetadataTools
2219
)
2320
import Kore.Log
2421
( KoreLogOptions (..)
25-
, SomeEntry (..)
26-
, logEntry
2722
, runLoggerT
2823
, swappableLogger
2924
, withLogger
3025
)
31-
import Kore.Log.ErrorException
32-
( errorException
33-
)
3426
import Kore.Log.KoreLogOptions
3527
( parseKoreLogOptions
3628
)
3729
import Kore.Log.WarnIfLowProductivity
3830
( warnIfLowProductivity
3931
)
40-
import qualified Kore.Reachability.Claim as Claim
32+
import Kore.Repl
33+
( someExceptionHandler
34+
, withConfigurationHandler
35+
)
4136
import Kore.Repl.Data
4237
import Kore.Step.SMT.Lemma
4338
import Kore.Syntax.Module
4439
( ModuleName (..)
4540
)
46-
import Kore.Unparser
47-
( unparseToString
48-
)
4941
import Options.Applicative
5042
( InfoMod
5143
, Parser
@@ -278,23 +270,6 @@ mainWithOptions
278270
exitReplHandler :: ExitCode -> Main ExitCode
279271
exitReplHandler = pure
280272

281-
someExceptionHandler :: SomeException -> Main ExitCode
282-
someExceptionHandler someException = do
283-
case fromException someException of
284-
Just (SomeEntry entry) -> logEntry entry
285-
Nothing -> errorException someException
286-
throwM someException
287-
288-
withConfigurationHandler :: Claim.WithConfiguration -> Main ExitCode
289-
withConfigurationHandler
290-
(Claim.WithConfiguration lastConfiguration someException) =
291-
do
292-
liftIO $
293-
hPutStrLn
294-
stderr
295-
("// Last configuration:\n" <> unparseToString lastConfiguration)
296-
throwM someException
297-
298273
mainModuleName :: ModuleName
299274
mainModuleName = moduleName definitionModule
300275

kore/src/Kore/Repl.hs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Maintainer : [email protected]
99
-}
1010
module Kore.Repl (
1111
runRepl,
12+
someExceptionHandler,
13+
withConfigurationHandler
1214
) where
1315

1416
import Control.Concurrent.MVar
@@ -260,28 +262,16 @@ runRepl
260262
if Graph.outdeg (Strategy.graph graph) node == 0
261263
then
262264
proveClaimStep claims axioms graph node
263-
& Exception.handle (withConfigurationHandler graph)
264-
& Exception.handle (someExceptionHandler graph)
265+
& Exception.handle (withConfigurationHandler' graph)
266+
& Exception.handle (someExceptionHandler' graph)
265267
else pure graph
266268

267-
withConfigurationHandler :: a -> Claim.WithConfiguration -> m a
268-
withConfigurationHandler
269-
_
270-
(Claim.WithConfiguration lastConfiguration someException)
271-
= do
272-
liftIO $
273-
hPutStrLn
274-
stderr
275-
("// Last configuration:\n" <> unparseToString lastConfiguration)
276-
Exception.throwM someException
269+
withConfigurationHandler' :: a -> Claim.WithConfiguration -> m a
270+
withConfigurationHandler' _ = withConfigurationHandler
277271

278-
someExceptionHandler :: a -> Exception.SomeException -> m a
279-
someExceptionHandler a someException = do
280-
case Exception.fromException someException of
281-
Just (Log.SomeEntry entry) ->
282-
Log.logEntry entry
283-
Nothing ->
284-
errorException someException
272+
someExceptionHandler' :: a -> Exception.SomeException -> m a
273+
someExceptionHandler' a someException = do
274+
someExceptionHandler someException
285275
pure a
286276

287277
replGreeting :: m ()
@@ -296,3 +286,27 @@ runRepl
296286
putStr $ "Kore (" <> show (unReplNode node) <> ")> "
297287
hFlush stdout
298288
getLine
289+
290+
someExceptionHandler
291+
:: MonadIO m
292+
=> Log.MonadLog m
293+
=> Exception.MonadThrow m
294+
=> Exception.SomeException -> m a
295+
someExceptionHandler someException = do
296+
case Exception.fromException someException of
297+
Just (Log.SomeEntry entry) -> Log.logEntry entry
298+
Nothing -> errorException someException
299+
Exception.throwM someException
300+
301+
withConfigurationHandler
302+
:: MonadIO m
303+
=> Exception.MonadThrow m
304+
=> Claim.WithConfiguration -> m a
305+
withConfigurationHandler
306+
(Claim.WithConfiguration lastConfiguration someException) =
307+
do
308+
liftIO $
309+
hPutStrLn
310+
stderr
311+
("// Last configuration:\n" <> unparseToString lastConfiguration)
312+
Exception.throwM someException

0 commit comments

Comments
 (0)