Browse Source

tag_wrap_error

main
pvincent 2 months ago
parent
commit
ea89764cf4
  1. 2
      app/controllers/hot_controller.rb
  2. 14
      lib/monkey_patches/action_dispatch/debug_exceptions.rb
  3. 39
      lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb
  4. 10
      lib/semantic/ansi_formatter.rb
  5. 14
      lib/semantic/tag_wrap_error.rb

2
app/controllers/hot_controller.rb

@ -1,6 +1,6 @@
class HotController < ApplicationController
def index
session[:toto1] = session[:toto1].nil? ? 'blabla' : nil
session[:toto1] = session[:toto1].nil? ? "id##{Random.rand(10)}" : nil
logger.info('callee')
logger.info(__callee__)
logger.info(__method__)

14
lib/monkey_patches/action_dispatch/debug_exceptions.rb

@ -1,14 +0,0 @@
require 'rails_semantic_logger/extensions/action_dispatch/debug_exceptions'
module ActionDispatch
# patched class to prevent deprecated message
class DebugExceptions
private
def log_error(_request, wrapper)
Rails.application.deprecators.silence do
ActionController::Base.logger.fatal(wrapper.exception)
end
end
end
end

39
lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb

@ -0,0 +1,39 @@
require 'action_dispatch/middleware/exception_wrapper'
require 'action_dispatch/routing/inspector'
require 'action_view'
module ActionDispatch
# patched class to prevent deprecated message
class DebugExceptions
private
def render_exception(request, exception, wrapper)
## PVINCENT's ADDITION for TagWrapError
log_error(request, wrapper)
if exception.is_a?(Semantic::TagWrapError)
backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner')
wrapper = ExceptionWrapper.new(backtrace_cleaner, exception.error)
end
# log_error(request, wrapper)
## END OF ADDITION
raise exception unless request.get_header('action_dispatch.show_detailed_exceptions')
begin
content_type = request.formats.first
rescue ActionDispatch::Http::MimeNegotiation::InvalidType
content_type = Mime[:text]
end
if api_request?(content_type)
render_for_api_request(content_type, wrapper)
else
render_for_browser_request(request, wrapper)
end
end
end
end

10
lib/semantic/ansi_formatter.rb

@ -164,7 +164,15 @@ module Semantic
def exception
return unless log.exception
exc = log.exception
if log.exception.is_a?(Semantic::TagWrapError)
exc_wrapper = log.exception
# puts "TAG_WRAP detected #{exc_wrapper.tag}"
exc = exc_wrapper.error
log.tags = Array.wrap(exc_wrapper.tag)
else
exc = log.exception
end
clazz = colorize("#{exc.class}\n", color_map[:fatal])
message = colorize(exc.message.chomp(''), color_map[:error])
backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace))

14
lib/semantic/tag_wrap_error.rb

@ -0,0 +1,14 @@
module Semantic
# custom Error for dispatching a remanent tag
class TagWrapError < StandardError
attr_reader :error, :tag
def initialize(tag, error)
@tag = tag
@error = error
super("my error message contains tag #{tag}")
end
def to_s = "TagWrap #{@tag}"
end
end
Loading…
Cancel
Save