Skip to content

Instantly share code, notes, and snippets.

@altherlex
Created May 9, 2022 17:59
Show Gist options
  • Save altherlex/6ea7c11ad035e935b9202ac2cbacb092 to your computer and use it in GitHub Desktop.
Save altherlex/6ea7c11ad035e935b9202ac2cbacb092 to your computer and use it in GitHub Desktop.
Catching rails/ruby upgrading errors
# module WarningHandlers
# module Rails
# class Deprecation < StandardError; end
# def self.register_deprecation_handler
# ActiveSupport::Notifications.subscribe('deprecation.rails') do |_name, _start, _finish, _id, payload|
# exception = Deprecation.new(payload[:message])
# Bugsnag.notify(exception) do |report|
# report.severity = 'warning'
# report.grouping_hash = payload[:message]
# end
# end
# end
# end
# end
#--------------------------
# module WarningHandlers
# module Ruby
# class Warning < StandardError; end
# def warn(message)
# STDERR.print(message)
# # exception = Warning.new(message)
# # puts "[RUBY DEPRECATION WARNING] #{message}"
# end
# end
# end
# if Rails.env.production? || Rails.env.staging?
# Warning.singleton_class.prepend(WarningHandlers::Ruby)
# end
#--------------------------
module Warning
# class DeprecationWarning < StandardError; end
def warn(msg)
puts "[RUBY-2.7 DEPRECATION WARNING] #{msg}".red
# STDERR.print(msg)
end
end
# class WarningsCollector < ParallelCollector
# def process
# filename = "warnings.txt"
# path = File.join(dir, filename)
# File.open(path, "a") do |f|
# @data.each do |message, origin|
# f.puts [message, origin].join("*^.^*") # ascii art so we can split on it later.
# end
# end
# script = File.absolute_path("../../../script/process-ruby-warnings", __FILE__)
# system(script, dir)
# end
# end
class MyClass
def initialize(part_1:, part_2:)
puts "#{part_1} #{part_2}"
end
end
MyClass.new(**{part_1:'It should trigger a', part_2:'ruby warn'})
Addressable::URI.escape("https://google.com?query_params=1")
@altherlex
Copy link
Author

#application.rb
if defined?(Bundler)
require_relative '../lib/warning_handlers/rails'
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment