arjan / decorator

Function decorators for Elixir
MIT License
385 stars 20 forks source link

Support `catch` as part of `do`-block #44

Closed tverlaan closed 3 years ago

tverlaan commented 3 years ago

Elixir automatically wraps the body of do in a try-block when one of the keywords rescue or catch is specified. They can also be used in conjunction with eachother.

This solves the following compilation error:

== Compilation error in file test/exception_test.exs ==
** (CompileError) test/exception_test.exs:32: unhandled operator ->
    (stdlib 3.13.2) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.13.2) lists.erl:1359: :lists.mapfoldl/3
    (stdlib 3.13.2) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.13.2) lists.erl:1359: :lists.mapfoldl/3

I chose the simplest and most straightforward solution by duplicating a bit of code. I think it's easier to maintain than a loop or reducer. Especially since the keywords are limited and should appear in a specific order:

warning: "catch" should always come after "rescue" in def
  test/exception_test.exs:36