ekmett / exceptions

mtl friendly exceptions
Other
49 stars 32 forks source link

API should be modified to take into account exception annotation propagation #100

Open mpickering opened 3 weeks ago

mpickering commented 3 weeks ago

The implementation and API of exceptions library should be modified to take into account the exception annotation propagation behaviour of catch.

CLC Proposal: https://github.com/haskell/core-libraries-committee/issues/202 GHC MR: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13302

In the next version of base there will be two versions of catch

In general it is better for exception utilities to be implemented in terms of catchNoPropagate, as the user does not care about the internal workings of utilities such as onException. They just want the backtrace of the

When you have multiple layers of error handling, without further action the call stacks will be quite large and messy. The rethrow in onException and bracket adds much additional noise to the error.

While handling default output name would overwrite the input file; must specify -o explicitly
  | Usage: For basic information, try the `--help' option.
  |
  | Package: ghc-9.11-inplace
  | Module: GHC.Utils.Panic
  | Type: GhcException
  |
  | While handling default output name would overwrite the input file; must specify -o explicitly
  |   | Usage: For basic information, try the `--help' option.
  |   |
  |   | Package: ghc-9.11-inplace
  |   | Module: GHC.Utils.Panic
  |   | Type: GhcException
  |   |
  |   | While handling default output name would overwrite the input file; must specify -o explicitly
  |   |   | Usage: For basic information, try the `--help' option.
  |   |   |
  |   |   | Package: ghc-9.11-inplace
  |   |   | Module: GHC.Utils.Panic
  |   |   | Type: GhcException
  |   |   |
  |   |   | HasCallStack backtrace:
  |   |   |   collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:92:13 in ghc-internal:GHC.Internal.Exception
  |   |   |   toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:84:32 in ghc-internal:GHC.Internal.Exception
  |   |   |   throw, called at compiler/GHC/Utils/Panic.hs:180:21 in ghc-9.11-inplace:GHC.Utils.Panic
  |   |
  |   | HasCallStack backtrace:
  |   |   bracket_, called at libraries/semaphore-compat/src/System/Semaphore.hs:320:23 in semaphore-compat-1.0.0-inplace:System.Semaphore
  |
  | HasCallStack backtrace:
  |   collectBacktraces, called at libraries/ghc-internal/src/GHC/Internal/Exception.hs:92:13 in ghc-internal:GHC.Internal.Exception
  |   toExceptionWithBacktrace, called at libraries/ghc-internal/src/GHC/Internal/IO.hs:284:11 in ghc-internal:GHC.Internal.IO
  |   throwIO, called at libraries/exceptions/src/Control/Monad/Catch.hs:371:12 in exceptions-0.10.7-inplace:Control.Monad.Catch
  |   throwM, called at libraries/exceptions/src/Control/Monad/Catch.hs:860:84 in exceptions-0.10.7-inplace:Control.Monad.Catch
  |   onException, called at compiler/GHC/Driver/Make.hs:2986:23 in ghc-9.11-inplace:GHC.Driver.Make

HasCallStack backtrace:
  bracket, called at compiler/GHC/Driver/Make.hs:2936:3 in ghc-9.11-inplace:GHC.Driver.Make
  bracket, called at compiler/GHC/Driver/Make.hs:2953:3 in ghc-9.11-inplace:GHC.Driver.Make
RyanGlScott commented 5 days ago

This sounds reasonable to me. Would you be willing to open a PR with an implementation?

mpickering commented 2 days ago

I think the patch is more complicated than some CPP, as the interface for exceptions should allow users to also control propagation behaviour?

RyanGlScott commented 2 days ago

To clarify, are you proposing that exceptions should offer a new API that allows deciding how exceptions are propagated? Or that it already does this?

If it's the latter, I'm not sure what part of the API does this. If it's the former, then I could use your help in figuring out what the API should look like, as this is new territory for me.