Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore_notifier_if settings are not respected in non-Rack usages such as background jobs. #518

Open
synth opened this issue Nov 17, 2021 · 1 comment

Comments

@synth
Copy link

synth commented Nov 17, 2021

Steps to reproduce

Given: ExceptionNotifier is configured with:

ignore_notifier_if: {
        email: ->(env, exception) { ... }
      },

And an exception notification is manually sent such as through a background worker with:

rescue => e
  ExceptionNotifier.notify_exception(e)
end

Expected behavior

The ignore_notifier block should be called and respected.

Actual behavior

The ignore_notifier block is not called nor respected. This is likely because the ignore block is only set via Rack, so any non-Rack usages of ExceptionNotifier will not retain the ignore settings.

System configuration

Rails version:
Rails v6+

Ruby version:
Ruby 2.7

@jorg-vr
Copy link

jorg-vr commented Nov 15, 2023

I have been struggling with the same issue
The problematic code was:

if options.key?(:ignore_notifier_if)
  rack_ignore_by_notifier = options.delete(:ignore_notifier_if)
  rack_ignore_by_notifier.each do |notifier, proc|
    ExceptionNotifier.ignore_notifier_if(notifier) do |exception, opts|
      opts.key?(:env) && proc.call(opts[:env], exception)
    end
  end
end

Thus the notifier does not work if env is not set

Giving any non null value for env solved the issue for me:

 ExceptionNotifier.notify_exception(e, env: request.env)

jorg-vr added a commit to dodona-edu/dodona that referenced this issue Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants