Skip to content

Commit 98777f8

Browse files
authored
Merge pull request #553 from IntersectMBO/wenkokke/add-fileformaterror-handler
test: add handler for FileFormatError to StateMachine
2 parents 6f99a27 + dd06260 commit 98777f8

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import Database.LSMTree.Extras.Generators (KeyForIndexCompact)
101101
import Database.LSMTree.Extras.NoThunks (propNoThunks)
102102
import Database.LSMTree.Internal (LSMTreeError (..))
103103
import qualified Database.LSMTree.Internal as R.Internal
104+
import Database.LSMTree.Internal.CRC32C (FileFormatError (..))
104105
import Database.LSMTree.Internal.Serialise (SerialisedBlob,
105106
SerialisedValue)
106107
import qualified Database.LSMTree.Model.IO as ModelIO
@@ -188,7 +189,11 @@ propLockstep_ModelIOImpl =
188189
env :: RealEnv ModelIO.Table IO
189190
env = RealEnv {
190191
envSession = session
191-
, envHandlers = [handler, diskFaultErrorHandler]
192+
, envHandlers = [
193+
handler
194+
, fileFormatErrorHandler
195+
, diskFaultErrorHandler
196+
]
192197
, envErrors = errsVar
193198
, envInjectFaultResults = faultsVar
194199
}
@@ -291,6 +296,7 @@ propLockstep_RealImpl_RealFS_IO tr =
291296
envSession = session
292297
, envHandlers = [
293298
realHandler @IO
299+
, fileFormatErrorHandler
294300
, diskFaultErrorHandler
295301
]
296302
, envErrors = errsVar
@@ -333,6 +339,7 @@ propLockstep_RealImpl_MockFS_IO tr =
333339
envSession = session
334340
, envHandlers = [
335341
realHandler @IO
342+
, fileFormatErrorHandler
336343
, diskFaultErrorHandler
337344
]
338345
, envErrors = errsVar
@@ -361,6 +368,7 @@ propLockstep_RealImpl_MockFS_IOSim tr actions =
361368
envSession = session
362369
, envHandlers = [
363370
realHandler @(IOSim s)
371+
, fileFormatErrorHandler
364372
, diskFaultErrorHandler
365373
]
366374
, envErrors = errsVar
@@ -434,6 +442,9 @@ realHandler = Handler $ pure . handler'
434442
handler' (ErrBlobRefInvalid _) = Just Model.ErrBlobRefInvalidated
435443
handler' _ = Nothing
436444

445+
-- | When combined with other handlers, 'diskFaultErrorHandler' has to go last
446+
-- because it matches on 'SomeException', an no other handlers are run after
447+
-- that. See the use of 'catches' in 'catchErr'.
437448
diskFaultErrorHandler :: Monad m => Handler m (Maybe Model.Err)
438449
diskFaultErrorHandler = Handler $ \e -> pure $
439450
if isDiskFault e
@@ -448,7 +459,7 @@ isDiskFault e
448459
= case reason of
449460
ReasonExitCaseException e' -> isDiskFault e' && all isDiskFault' es
450461
ReasonExitCaseAbort -> False
451-
| Just (e' :: ActionError)<- fromException e
462+
| Just (e' :: ActionError) <- fromException e
452463
= isDiskFault' (getActionError e')
453464
| Just FsError{} <- fromException e
454465
= True
@@ -458,6 +469,12 @@ isDiskFault e
458469
isDiskFault' :: forall e. Exception e => e -> Bool
459470
isDiskFault' = isDiskFault . toException
460471

472+
fileFormatErrorHandler :: Monad m => Handler m (Maybe Model.Err)
473+
fileFormatErrorHandler = Handler $ pure . handler'
474+
where
475+
handler' :: FileFormatError -> Maybe Model.Err
476+
handler' e = Just (Model.ErrFsError (displayException e))
477+
461478
createSystemTempDirectory :: [Char] -> IO (FilePath, HasFS IO HandleIO, HasBlockIO IO HandleIO)
462479
createSystemTempDirectory prefix = do
463480
systemTempDir <- getCanonicalTemporaryDirectory

0 commit comments

Comments
 (0)