Skip to content

Commit

Permalink
Handle DiffusionError of ExitCode in toplevelExceptionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Jun 1, 2023
1 parent f64ef88 commit e70aee0
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bench/locli/locli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ library
, optparse-generic
, ouroboros-consensus
-- for Data.SOP.Strict:
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, process
, quiet
Expand Down
2 changes: 1 addition & 1 deletion bench/tx-generator/tx-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ library
, ouroboros-consensus >= 0.6
, ouroboros-consensus-cardano >= 0.5
, ouroboros-consensus-diffusion >= 0.5.1
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, ouroboros-network-framework
, ouroboros-network-protocols
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/cardano-node.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ library
, ouroboros-consensus-diffusion >= 0.5.1
, ouroboros-consensus-protocol >= 0.5
, ouroboros-network-api
, ouroboros-network >= 0.6
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-framework >= 0.6
, ouroboros-network-protocols
, prettyprinter
Expand Down Expand Up @@ -248,7 +248,7 @@ test-suite cardano-node-test
, ouroboros-consensus
, ouroboros-consensus-cardano
, ouroboros-consensus-diffusion
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, text
, time
Expand Down
19 changes: 17 additions & 2 deletions cardano-node/src/Cardano/Node/Handlers/TopLevel.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE TypeApplications #-}

module Cardano.Node.Handlers.TopLevel
( toplevelExceptionHandler
) where
Expand Down Expand Up @@ -53,6 +55,7 @@ import System.Environment
import System.Exit
import System.IO

import qualified Ouroboros.Network.Diffusion as Network

-- | An exception handler to use for a program top level, as an alternative to
-- the default top level handler provided by GHC.
Expand All @@ -70,7 +73,8 @@ toplevelExceptionHandler prog = do
hSetBuffering stderr LineBuffering
catches prog [
Handler rethrowAsyncExceptions
, Handler rethrowExitCode
, Handler rethrowExitCode -- TODO this is possibly not needed anymore
, Handler rethrowDiffusionErrorExceptionInLinkedThreadExitSuccess
, Handler handleSomeException
]
where
Expand All @@ -79,7 +83,7 @@ toplevelExceptionHandler prog = do
-- then we rethrow ExitSuccess. This happens for example when using the
-- `--shutdown-on-slot-synced` option.
rethrowAsyncExceptions :: SomeAsyncException -> IO a
rethrowAsyncExceptions full@(SomeAsyncException e) = do
rethrowAsyncExceptions full@(SomeAsyncException e) =
case fromException (toException e) of
Just (ExceptionInLinkedThread _ eInner)
| Just ExitSuccess <- fromException eInner
Expand All @@ -91,6 +95,17 @@ toplevelExceptionHandler prog = do
rethrowExitCode :: ExitCode -> IO a
rethrowExitCode = throwIO

rethrowDiffusionErrorExceptionInLinkedThreadExitSuccess :: Network.Failure -> IO a
rethrowDiffusionErrorExceptionInLinkedThreadExitSuccess full =
case full of
Network.DiffusionError e ->
case fromException (toException e) of
Just (ExceptionInLinkedThread _ eInner)
| Just exitCode <- fromException eInner
-> throwIO @ExitCode exitCode
_ -> throwIO full
_ -> throwIO full

-- Print all other exceptions
handleSomeException :: SomeException -> IO a
handleSomeException e = do
Expand Down
2 changes: 1 addition & 1 deletion cardano-submit-api/cardano-submit-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library
, network
, optparse-applicative-fork
, ouroboros-consensus-cardano
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-protocols
, prometheus
, servant
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ library
, hedgehog-extras ^>= 0.4.5.1
, mtl
, optparse-applicative-fork
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, process
, random
Expand Down
4 changes: 2 additions & 2 deletions cardano-tracer/cardano-tracer.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ library
, filepath
, mime-mail
, optparse-applicative
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, ouroboros-network-framework
, signal
Expand Down Expand Up @@ -358,7 +358,7 @@ test-suite cardano-tracer-test-ext
, generic-data
, Glob
, optparse-applicative-fork
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, ouroboros-network-framework
, process
Expand Down
4 changes: 2 additions & 2 deletions trace-dispatcher/trace-dispatcher.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ library
, hostname
, network
, optparse-applicative-fork
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, ouroboros-network-api
, ouroboros-network-framework
, serialise
Expand Down Expand Up @@ -147,7 +147,7 @@ test-suite trace-dispatcher-test
, generic-data
, hostname
, optparse-applicative
, ouroboros-network
, ouroboros-network ^>= 0.8.1.0
, text
, stm
, tasty
Expand Down

0 comments on commit e70aee0

Please sign in to comment.