From 3e5817e99e69a3ecb8faaf9078b73cc7abae25a0 Mon Sep 17 00:00:00 2001 From: pvincent Date: Mon, 16 Sep 2024 23:57:45 +0400 Subject: [PATCH] bootstrap, however on error no toto1 session --- config/initializers/semantic_logger.rb | 7 +++ .../middleware/debug_exceptions.rb | 50 ++++++++++--------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/config/initializers/semantic_logger.rb b/config/initializers/semantic_logger.rb index d357092..d2c3102 100644 --- a/config/initializers/semantic_logger.rb +++ b/config/initializers/semantic_logger.rb @@ -10,7 +10,14 @@ end Rails.configuration.after_initialize do Semantic::InstrumentationManager.clear + + bootstrap = [{ kind: :restored, constant: 'ACTION_VIEW', type: :boolean, old_value: false, new_value: true }, + { kind: :restored, constant: 'ACTION_CONTROLLER', type: :boolean, old_value: false, new_value: true }] + im ||= Semantic::InstrumentationManager.new + im.process(bootstrap) + ActiveSupport::Notifications.subscribe('rolling.live_constant') do |event| + puts event.payload[:changes].inspect im.process(event.payload[:changes]) rescue StandardError => e puts e diff --git a/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb b/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb index bbaff35..431944c 100644 --- a/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb +++ b/lib/monkey_patches/action_dispatch/middleware/debug_exceptions.rb @@ -3,33 +3,35 @@ require 'action_dispatch/routing/inspector' require 'action_view' module ActionDispatch - # THIS IS A HACK TO unwrap TagWrapError when detected! - # TagWrapError contains a 'tag' for SemanticLogger and the cause itself - class DebugExceptions - private + module Middleware + # THIS IS A HACK TO unwrap TagWrapError when detected! + # TagWrapError contains a 'tag' for SemanticLogger and the cause itself + 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 - ## HERE it was commented off - # log_error(request, wrapper) - ## END OF ADDITION + 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 + ## HERE it was commented off + # log_error(request, wrapper) + ## END OF ADDITION - raise exception unless request.get_header('action_dispatch.show_detailed_exceptions') + 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) + 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