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

webhook notifier.IOError: not opened for reading #541

Open
arvindkushwah9 opened this issue Aug 8, 2024 · 1 comment
Open

webhook notifier.IOError: not opened for reading #541

arvindkushwah9 opened this issue Aug 8, 2024 · 1 comment

Comments

@arvindkushwah9
Copy link

arvindkushwah9 commented Aug 8, 2024

I have upgraded from ruby 2.7.5 to ruby-3.2.0 and we are getting following error.

ERROR:

W, [2024-08-07T13:00:15.480470 #52435] WARN -- : An error occurred when sending a notification using 'webhook' notifier.IOError: not opened for reading
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:78:in read' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:78:in content_body'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:47:in block in generate_multipart' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:38:in each'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:38:in inject' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:38:in generate_multipart'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request/body.rb:19:in call' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request.rb:241:in setup_raw_request'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty/request.rb:148:in perform' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty.rb:613:in perform_request'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty.rb:543:in post' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/httparty-0.20.0/lib/httparty.rb:650:in post'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier/webhook_notifier.rb:47:in block in call' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier/base_notifier.rb:13:in send_notice'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier/webhook_notifier.rb:46:in call' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:161:in fire_notification'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:70:in block in notify_exception' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:68:in each'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:68:in notify_exception' .rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notification/rack.rb:59:in rescue in call'
.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/exception_notification-4.5.0/lib/exception_notification/rack.rb:48:in `call'

System configuration

Rails version:
Rails 6.1.4.6
Ruby version:
3.2.0

Other configurations:

 Rails.application.config.middleware.use ExceptionNotification::Rack,
                                      :ignore_exceptions => [],
                                      webhook: {
                                      url: "https://examle.com/webhook/tickets",
                                      http_method: :post,
                                      basic_auth: {
                                        username: 'xxxx',
                                        password: 'xxxx!'
                                      }
                                    }
@arvindkushwah9
Copy link
Author

arvindkushwah9 commented Aug 8, 2024

I found in my investigation this is causing an error in file lib/exception_notifier/webhook_notifier.rb
options[:body][:environment] = request.filtered_env

`# frozen_string_literal: true

require 'action_dispatch'
require 'active_support/core_ext/time'

module ExceptionNotifier
class WebhookNotifier < BaseNotifier
def initialize(options)
super
@default_options = options
end

def call(exception, options = {})
  env = options[:env]

  options = options.reverse_merge(@default_options)
  url = options.delete(:url)
  http_method = options.delete(:http_method) || :post

  options[:body] ||= {}
  options[:body][:server] = Socket.gethostname
  options[:body][:process] = $PROCESS_ID
  options[:body][:rails_root] = Rails.root if defined?(Rails) && Rails.respond_to?(:root)
  options[:body][:exception] = {
    error_class: exception.class.to_s,
    message: exception.message.inspect,
    backtrace: exception.backtrace
  }
  options[:body][:data] = (env && env['exception_notifier.exception_data'] || {}).merge(options[:data] || {})

  unless env.nil?
    request = ActionDispatch::Request.new(env)

    request_items = {
      url: request.original_url,
      http_method: request.method,
      ip_address: request.remote_ip,
      parameters: request.filtered_parameters,
      timestamp: Time.current
    }

    options[:body][:request] = request_items
    options[:body][:session] = request.session
    options[:body][:environment] = request.filtered_env
  end
  send_notice(exception, options, nil, @default_options) do |_, _|
    HTTParty.send(http_method, url, options)
  end
end

end
end`

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

1 participant