liefery-it-legacy / bugsnex

API client and logger for Bugsnag
MIT License
10 stars 2 forks source link

Add configuration option for handle_errors to be a noop #21

Open kisp opened 7 years ago

kisp commented 7 years ago

This would be useful for development.

Allowing the macro handle_errors at compile time to be defined (configured to essentially act) like

  defmacro handle_errors(metadata \\ quote(do: %{}), do: block) do
    quote do
      unquote(block)
    end
  end

instead of

defmacro handle_errors(metadata \\ quote(do: %{}), do: block) do
    quote do
      try do
        unquote(block)
      rescue
        e ->
          Bugsnex.notify(e, System.stacktrace, unquote(metadata))
          raise e
      end
    end
  end

thus avoiding to wrap the body with a try/rescue, leads to stacktraces pointing to the real location of the exception.

kisp commented 7 years ago

I'm not sure what's the best way to pass this configuration option. Possibly, it can be passed as an option in the

require Bugsnex

statement.

I suppose that the value of Mix.env can be used at compile time, but I'm not sure.