Skip to content

Commit a63081e

Browse files
committed
Issue #755: print an assertion failure message
This should help get a sense of *why* the assertion is failing
1 parent 1bbb9cc commit a63081e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src-prototypes/ScheduledMerges.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,21 @@ assert p x = Exc.assert p (const x callStack)
526526
assertST :: HasCallStack => Bool -> ST s ()
527527
assertST p = assert p $ pure ()
528528

529+
assertWithMsg :: HasCallStack => Maybe String -> a -> a
530+
assertWithMsg = assert . p
531+
where
532+
p Nothing = True
533+
p (Just msg) = error $ "Assertion failed: " <> msg
534+
535+
assertWithMsgM :: (HasCallStack, Monad m) => Maybe String -> m ()
536+
assertWithMsgM mmsg = assertWithMsg mmsg $ pure ()
537+
538+
leq :: (Show a, Ord a) => a -> a -> Maybe String
539+
leq x y = if x <= y then Nothing else Just $
540+
printf "Expected x <= y, but got %s > %s"
541+
(show x)
542+
(show y)
543+
529544
-------------------------------------------------------------------------------
530545
-- Run sizes
531546
--
@@ -1461,7 +1476,7 @@ newLevelMerge _ _ _ _ _ [r] = pure (Single r)
14611476
newLevelMerge tr conf@LSMConfig{..} level mergePolicy mergeType rs = do
14621477
assertST (length rs `elem` [configSizeRatio, configSizeRatio + 1])
14631478
mergingRun@(MergingRun _ physicalDebt _) <- newMergingRun mergeType rs
1464-
assertST (totalDebt physicalDebt <= maxPhysicalDebt)
1479+
assertWithMsgM $ leq (totalDebt physicalDebt) maxPhysicalDebt
14651480
traceWith tr MergeStartedEvent {
14661481
mergePolicy,
14671482
mergeType,

0 commit comments

Comments
 (0)