arjan / decorator

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

OTP 20 / Elixir 1.5.0-rc.0 Rescue Emits Compiler Warning #12

Closed asummers closed 6 years ago

asummers commented 7 years ago

Hello! I suspect this is similar to #11 but when a function is decorated and has a function body with a rescue, and the rescue reraises System.stacktrace the new OTP 20 builds emit warnings.

This works:

  @decorate decorated()
  @spec fetch!(module, binary) :: any | no_return
  def fetch!(model, pkey) do
    try do
     Repo.get!(model, pkey)
    rescue
      _exception in Ecto.NoResultsError ->
        reraise Errors.NotFound, System.stacktrace
      _exception in Ecto.Query.CastError ->
        reraise Errors.BadRequest.InvalidID, [id: pkey], System.stacktrace
    end
  end

This doesn't:

  @decorate decorated()
  @spec fetch!(module, binary) :: any | no_return
  def fetch!(model, pkey) do
   Repo.get!(model, pkey)
  rescue
    _exception in Ecto.NoResultsError ->
      reraise Errors.NotFound, System.stacktrace
    _exception in Ecto.Query.CastError ->
      reraise Errors.BadRequest.InvalidID, [id: pkey], System.stacktrace
  end

This emits:

warning: erlang:get_stacktrace/0 used following a 'try' expression may stop working in a future release. (Use it inside 'try'.)
  web/plugs/load_resource.ex:54

warning: erlang:get_stacktrace/0 used in the wrong part of 'try' expression. (Use it in the block between 'catch' and 'end'.)
  web/plugs/load_resource.ex:54

warning: erlang:get_stacktrace/0 used following a 'try' expression may stop working in a future release. (Use it inside 'try'.)
  web/plugs/load_resource.ex:56

warning: erlang:get_stacktrace/0 used in the wrong part of 'try' expression. (Use it in the block between 'catch' and 'end'.)
  web/plugs/load_resource.ex:56

Looking through the OTP commits, it looks like https://github.com/erlang/otp/pull/1453/files is the offending one, however both of those should probably emit the same code. Please let me know if I can provide any further details.

Thank you

arjan commented 7 years ago

Just to be clear, without a decorator this warning is not emitted, I guess?

asummers commented 7 years ago

Correct.

On Fri, Jul 7, 2017, 7:56 AM Arjan Scherpenisse notifications@github.com wrote:

Just to be clear, without a decorator this warning is not emitted, I guess?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/arjan/decorator/issues/12#issuecomment-313673519, or mute the thread https://github.com/notifications/unsubscribe-auth/AAywoJqwju1cH1CR1WKNoOIMYVdEqzdzks5sLirkgaJpZM4OPv9m .

deadtrickster commented 7 years ago

This might be related (OTP 20 bug):

https://github.com/elixir-lang/elixir/issues/6539 https://bugs.erlang.org/browse/ERL-478

arjan commented 6 years ago

I think this is now resolved. Cant reproduce it in the latest release.