parsonsmatt / annotated-exception

Machinery for throwing and catching exceptions with some annotation.
BSD 3-Clause "New" or "Revised" License
32 stars 3 forks source link

Add `Control.exception.evaluate` equivalent #22

Open codygman opened 1 year ago

codygman commented 1 year ago

I'm moving our codebase to use annotated-exceptions and we have the following:

expectError :: a -> Test.Expectation
expectError = flip Hspec.shouldThrow Hspec.anyErrorCall . Exception.evaluate

I'm just starting to understand annotated-exception, so not quite sure how to make this work yet.

I think if evaluate existed my migration path could just be changing the import though.

If so, I think this would be useful for the library since other users likely find themselves in similar situations.

parsonsmatt commented 1 year ago

Seems reasonable! I think a first pass implementation would be like

evaluate :: (NFData a, HasCallStack, MonadIO m) => a -> m a
evaluate a = withFrozenCallStack checkpointCallStack $ liftIO $ Control.Exception.evaluate a

if you want to bake that in, or make a PR