Gabriella439 / Gabriella439/Haskell-Pipes-Safe-Library
Should onException catch?
- Dominant language
- Haskell
- Stars
- 27
- Forks
- 22
- Avg merge
- 12d 10h
- Merged PRs (30d)
- 1
Description
I pointed out in [this reddit comment](https://old.reddit.com/r/haskell/comments/1f35f92/how_is_pipessafe_supposed_to_work/lkc1hsf/) that the `pipes-safe` version of `onException` is implemented with `register`/`release`:
https://github.com/Gabriella439/Haskell-Pipes-Safe-Library/blob/b76b3b38500da8c1c9e41525a5bf453ccd50a12b/src/Pipes/Safe.hs#L412-L417
but [the version in Control.Exception](https://hackage.haskell.org/package/base-4.20.0.1/docs/Control-Exception.html#v:onException) is implemented with `catch`. This leads to the surprising behaviour noted in that thread; in the `base` version of `finally`, the final action will be run before the exception is propagated upward, whereas in the `pipes-safe` version the final action is only guaranteed to be run when the `MonadSafe` scope is exited.
I haven't tested this yet, but could this library's version of `onException` be changed to something like:
```
onException :: (MonadSafe m) => m a -> Base m b -> m a
m1 `onException` io = do
key <- register (io >> return ())
r <- m1 `catch` (\e -> release key >> throwM (e :: SomeException))
release key
return r
```
so `finally` and related `pipes-safe` functions will behave more like their `base` counterparts?
Also, the documentation of `Control.Exception.onException` claims that it "only performs the final action if there was an exception raised by the computation", but it looks like the `pipes-safe` version will always run the final action (which is how `Control.Exception.finally` behaves). The documentation should probably mention that if that is intentional.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/Pipes/Safe.hs around lines 412-417 and compare its onException behavior with Control.Exception.onException and finally. Reproduce the exception and scope-exit behavior with a focused test; the work is done when the intended behavior is decided, verified, and the documentation accurately describes whether the final action runs only after an exception or on every scope exit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100