haskell / cabal-cache

CI assistant
BSD 3-Clause "New" or "Revised" License
45 stars 10 forks source link

Use oops for error handling #213

Closed newhoggy closed 1 year ago

hasufell commented 1 year ago

Why not excepts? I believe it's more mature.

newhoggy commented 1 year ago

Why not excepts? I believe it's more mature.

I tried that first but I didn't get very far. One of the reasons I couldn't get it working is there isn't a combinator that preserves the transformer stack. See snatchM, which is the same as catchM except the exception is not plucked from the list of possible errors.

There are possibly other reasons like support for MonadError, decent error messages, good type inference, flipped catch arguments (which has better ergonomics).

I have also tried and rejected plucky because it's error messages were very poor.

I even tried fused-effects but got very stuck when I couldn't get it to work with ResourceT.

hasufell commented 1 year ago

One of the reasons I couldn't get it working is there isn't a combinator that preserves the transformer stack. See snatchM, which is the same as catchM except the exception is not plucked from the list of possible errors.

Not sure I understand what you mean with preserving the transformer stack. Are you looking for onE?

There are possibly other reasons like support for MonadError, decent error messages, good type inference, flipped catch arguments (which has better ergonomics).

Upstream has been responsive and willing to add new instances: https://github.com/haskus/packages/issues/34

Good type inference isn't really possible with open sum types.

newhoggy commented 1 year ago

onE seems right.

Let me finish this restructuring and we can take a step back and re-evaluate.

newhoggy commented 1 year ago

This is coded up. Next step is to add some integration tests.

newhoggy commented 1 year ago

Includes integration tests now, so I'm more comfortable with refactoring not breaking anything accidentally.

newhoggy commented 1 year ago

Removed all the pre-oops code.

This PR is ready.

prednaz commented 1 year ago

may i ask why you do not just use plucky? oops is just another implementation of the same interface.

newhoggy commented 1 year ago

plucky was actually the first out of many libraries I tried. I found it had poor error messages and type inference (for example using HLS to infer type signatures) was poor which made it difficult to use.

oops also has catch combinators with flipped arguments, which is preferable because it allows me to cleanly stack multiple handlers on the same expression without using parentheses. The reliance of parentheses is particularly problematic because adding or removing handlers touches more lines than I'd like.

newhoggy commented 1 year ago

I wrote some extensive notes on why I chose to go with oops in another PR: https://github.com/input-output-hk/cardano-node/pull/4777