{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Ouroboros.Consensus.Node.Exit (
ExitFailure
, exitReasontoExitFailure
, ExitReason (..)
, toExitReason
) where
import Control.Exception (AsyncException (..), SomeException,
fromException)
import Data.Proxy (Proxy)
import Data.Typeable (Typeable)
import Control.Monad.Class.MonadAsync (ExceptionInLinkedThread (..))
import Ouroboros.Consensus.Block (StandardHash)
import Ouroboros.Consensus.Storage.ChainDB.API (ChainDbFailure (..))
import Ouroboros.Consensus.Storage.FS.API.Types (FsError (..),
FsErrorType (..))
import Ouroboros.Consensus.Storage.ImmutableDB.API (ImmutableDBError)
import qualified Ouroboros.Consensus.Storage.ImmutableDB.API as ImmutableDB
import Ouroboros.Consensus.Storage.VolatileDB (VolatileDBError)
import qualified Ouroboros.Consensus.Storage.VolatileDB as VolatileDB
import Ouroboros.Consensus.Node.DbMarker (DbMarkerError)
type ExitFailure = Int
exitReasontoExitFailure :: ExitReason -> ExitFailure
exitReasontoExitFailure :: ExitReason -> ExitFailure
exitReasontoExitFailure = \case
ExitReason
ConfigurationError -> ExitFailure
3
ExitReason
WrongDatabase -> ExitFailure
4
ExitReason
DiskFull -> ExitFailure
5
ExitReason
InsufficientPermissions -> ExitFailure
6
ExitReason
NoNetwork -> ExitFailure
7
ExitReason
Killed -> ExitFailure
1
ExitReason
DatabaseCorruption -> ExitFailure
2
ExitReason
Other -> ExitFailure
2
data ExitReason =
Killed
| ConfigurationError
| WrongDatabase
| DiskFull
| InsufficientPermissions
| NoNetwork
| DatabaseCorruption
| Other
toExitReason ::
forall blk. (Typeable blk, StandardHash blk)
=> Proxy blk
-> SomeException
-> ExitReason
toExitReason :: Proxy blk -> SomeException -> ExitReason
toExitReason Proxy blk
pb SomeException
e
| Just (AsyncException
e' :: AsyncException) <- SomeException -> Maybe AsyncException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= case AsyncException
e' of
AsyncException
ThreadKilled -> ExitReason
Killed
AsyncException
UserInterrupt -> ExitReason
Killed
AsyncException
_ -> ExitReason
Other
| Just (ExceptionInLinkedThread String
_ SomeException
e') <- SomeException -> Maybe ExceptionInLinkedThread
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= Proxy blk -> SomeException -> ExitReason
forall blk.
(Typeable blk, StandardHash blk) =>
Proxy blk -> SomeException -> ExitReason
toExitReason Proxy blk
pb SomeException
e'
| Just (DbMarkerError
_ :: DbMarkerError) <- SomeException -> Maybe DbMarkerError
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= ExitReason
WrongDatabase
| Just (ChainDbFailure blk
e' :: ChainDbFailure blk) <- SomeException -> Maybe (ChainDbFailure blk)
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= case ChainDbFailure blk
e' of
LgrDbFailure FsError
fe -> FsError -> ExitReason
fsError FsError
fe
ChainDbFailure blk
_ -> ExitReason
DatabaseCorruption
| Just (VolatileDBError blk
e' :: VolatileDBError blk) <- SomeException -> Maybe (VolatileDBError blk)
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= case VolatileDBError blk
e' of
VolatileDB.UnexpectedFailure UnexpectedFailure blk
uf -> UnexpectedFailure blk -> ExitReason
volatileDbUnexpectedFailure UnexpectedFailure blk
uf
VolatileDBError blk
_ -> ExitReason
Other
| Just (ImmutableDBError blk
e' :: ImmutableDBError blk) <- SomeException -> Maybe (ImmutableDBError blk)
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= case ImmutableDBError blk
e' of
ImmutableDB.UnexpectedFailure UnexpectedFailure blk
uf -> UnexpectedFailure blk -> ExitReason
immutableDbUnexpectedFailure UnexpectedFailure blk
uf
ImmutableDBError blk
_ -> ExitReason
Other
| Just (FsError
e' :: FsError) <- SomeException -> Maybe FsError
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
e
= FsError -> ExitReason
fsError FsError
e'
| Bool
otherwise
= ExitReason
Other
where
immutableDbUnexpectedFailure :: ImmutableDB.UnexpectedFailure blk -> ExitReason
immutableDbUnexpectedFailure :: UnexpectedFailure blk -> ExitReason
immutableDbUnexpectedFailure = \case
ImmutableDB.FileSystemError FsError
fe -> FsError -> ExitReason
fsError FsError
fe
UnexpectedFailure blk
_ -> ExitReason
DatabaseCorruption
volatileDbUnexpectedFailure :: VolatileDB.UnexpectedFailure blk -> ExitReason
volatileDbUnexpectedFailure :: UnexpectedFailure blk -> ExitReason
volatileDbUnexpectedFailure = \case
VolatileDB.FileSystemError FsError
fe -> FsError -> ExitReason
fsError FsError
fe
UnexpectedFailure blk
_ -> ExitReason
DatabaseCorruption
fsError :: FsError -> ExitReason
fsError :: FsError -> ExitReason
fsError FsError { FsErrorType
fsErrorType :: FsError -> FsErrorType
fsErrorType :: FsErrorType
fsErrorType } = case FsErrorType
fsErrorType of
FsErrorType
FsDeviceFull -> ExitReason
DiskFull
FsErrorType
FsInsufficientPermissions -> ExitReason
InsufficientPermissions
FsErrorType
_ -> ExitReason
DatabaseCorruption