Skip to content

Commit dd06260

Browse files
committed
QLS: use fileFormatErrorHandler before diskFaultErrorHandler
1 parent 052624e commit dd06260

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ propLockstep_ModelIOImpl =
189189
env :: RealEnv ModelIO.Table IO
190190
env = RealEnv {
191191
envSession = session
192-
, envHandlers = [handler, diskFaultErrorHandler, fileFormatErrorHandler]
192+
, envHandlers = [
193+
handler
194+
, fileFormatErrorHandler
195+
, diskFaultErrorHandler
196+
]
193197
, envErrors = errsVar
194198
, envInjectFaultResults = faultsVar
195199
}
@@ -292,8 +296,8 @@ propLockstep_RealImpl_RealFS_IO tr =
292296
envSession = session
293297
, envHandlers = [
294298
realHandler @IO
295-
, diskFaultErrorHandler
296299
, fileFormatErrorHandler
300+
, diskFaultErrorHandler
297301
]
298302
, envErrors = errsVar
299303
, envInjectFaultResults = faultsVar
@@ -335,8 +339,8 @@ propLockstep_RealImpl_MockFS_IO tr =
335339
envSession = session
336340
, envHandlers = [
337341
realHandler @IO
338-
, diskFaultErrorHandler
339342
, fileFormatErrorHandler
343+
, diskFaultErrorHandler
340344
]
341345
, envErrors = errsVar
342346
, envInjectFaultResults = faultsVar
@@ -364,8 +368,8 @@ propLockstep_RealImpl_MockFS_IOSim tr actions =
364368
envSession = session
365369
, envHandlers = [
366370
realHandler @(IOSim s)
367-
, diskFaultErrorHandler
368371
, fileFormatErrorHandler
372+
, diskFaultErrorHandler
369373
]
370374
, envErrors = errsVar
371375
, envInjectFaultResults = faultsVar
@@ -438,6 +442,9 @@ realHandler = Handler $ pure . handler'
438442
handler' (ErrBlobRefInvalid _) = Just Model.ErrBlobRefInvalidated
439443
handler' _ = Nothing
440444

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'.
441448
diskFaultErrorHandler :: Monad m => Handler m (Maybe Model.Err)
442449
diskFaultErrorHandler = Handler $ \e -> pure $
443450
if isDiskFault e
@@ -452,7 +459,7 @@ isDiskFault e
452459
= case reason of
453460
ReasonExitCaseException e' -> isDiskFault e' && all isDiskFault' es
454461
ReasonExitCaseAbort -> False
455-
| Just (e' :: ActionError)<- fromException e
462+
| Just (e' :: ActionError) <- fromException e
456463
= isDiskFault' (getActionError e')
457464
| Just FsError{} <- fromException e
458465
= True
@@ -463,17 +470,10 @@ isDiskFault e
463470
isDiskFault' = isDiskFault . toException
464471

465472
fileFormatErrorHandler :: Monad m => Handler m (Maybe Model.Err)
466-
fileFormatErrorHandler = Handler $ \e -> pure $
467-
if isFileFormatError e
468-
then Just (Model.ErrFsError (displayException e))
469-
else Nothing
470-
471-
isFileFormatError :: SomeException -> Bool
472-
isFileFormatError e
473-
| Just (FileFormatError _file _msg) <- fromException e
474-
= True
475-
| otherwise
476-
= False
473+
fileFormatErrorHandler = Handler $ pure . handler'
474+
where
475+
handler' :: FileFormatError -> Maybe Model.Err
476+
handler' e = Just (Model.ErrFsError (displayException e))
477477

478478
createSystemTempDirectory :: [Char] -> IO (FilePath, HasFS IO HandleIO, HasBlockIO IO HandleIO)
479479
createSystemTempDirectory prefix = do

0 commit comments

Comments
 (0)