Browse Source

TagWrapError in BasicFormatter

main
pvincent 4 weeks ago
parent
commit
541a7b936a
  1. 4
      app/controllers/scores_controller.rb
  2. 2
      config/environments/development.rb
  3. 5
      lib/semantic/abstract_formatter.rb
  4. 28
      lib/semantic/basic_formatter.rb
  5. 6
      lib/semantic/fancy_formatter.rb

4
app/controllers/scores_controller.rb

@ -5,7 +5,7 @@ class ScoresController < ApplicationController
before_action :set_score, only: %i[show edit update destroy]
def index
logger.info('inside controller22')
logger.info('inside controller2')
@q = Score.all.ransack(q_params)
@pagy, @scores = pagy(@q.result)
end
@ -37,6 +37,8 @@ class ScoresController < ApplicationController
end
def destroy
zazaz
@score.destroy!
redirect_to scores_url, notice: 'Score was successfully destroyed.', status: :see_other

2
config/environments/development.rb

@ -78,6 +78,6 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
routes.default_url_options[:port] = ARGV[1] # ie: Procfile.dev --port PORT
routes.default_url_options[:host] = '127.0.0.1'
# config.x.semantic.formatter = 'Semantic::BasicFormatter'
config.x.semantic.formatter = 'Semantic::FancyFormatter'
config.x.semantic.formatter = 'Semantic::BasicFormatter'
end

5
lib/semantic/abstract_formatter.rb

@ -0,0 +1,5 @@
module Semantic
# Abstract colorized formatter
class AbstractFormatter < SemanticLogger::Formatters::Color
end
end

28
lib/semantic/basic_formatter.rb

@ -1,6 +1,6 @@
module Semantic
# My Custom colorized formatter
class BasicFormatter < SemanticLogger::Formatters::Color
class BasicFormatter < AbstractFormatter
ANSI_REVERSED_WARNING = "\e[0;30;43m".freeze
ANSI_REVERSED_ERROR = "\e[1;30;41m".freeze
ANSI_GRAY = "\e[90m".freeze
@ -57,15 +57,35 @@ module Semantic
return unless log.exception
root_path = Rails.root.to_s
backtrace = log.exception.backtrace.select do |line|
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
backtrace = exc.backtrace.select do |line|
line.starts_with?(root_path)
end
if backtrace.count.positive?
"-- #{ANSI_REVERSED_ERROR}#{log.exception.class}#{color_map.clear} #{color}#{log.exception.message}#{color_map.clear}#{SemanticLogger::AnsiColors::WHITE}\n\t#{backtrace.join("\n\t")}#{color_map.clear}\n\n"
"-- #{ANSI_REVERSED_ERROR}#{exc.class}#{color_map.clear} #{color}#{exc.message}#{color_map.clear}#{SemanticLogger::AnsiColors::WHITE}\n\t#{backtrace.join("\n\t")}#{color_map.clear}\n\n"
else
"-- #{ANSI_REVERSED_ERROR}#{log.exception.class}: #{log.exception.message}#{color_map.clear}\n\n"
"-- #{ANSI_REVERSED_ERROR}#{exc.class}: #{exc.message}#{color_map.clear}\n\n"
end
# TODO: remove me
# clazz = colorize("#{exc.class}\n", color_map[:fatal])
# message = colorize(exc.message.chomp(''), color_map[:error])
# # TODO: backtrace_cleaner might be optionally disable from Live::Constant
# backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace))
# "#{clazz}#{message}#{backtrace}"
end
def call(log, logger)

6
lib/semantic/fancy_formatter.rb

@ -4,7 +4,7 @@ require 'json'
module Semantic
# wraps meanwhile takes care of ansi colors
class FancyFormatter < SemanticLogger::Formatters::Color
class FancyFormatter < AbstractFormatter
include AnsiColors
TAG_NONE = ''.freeze
@ -180,7 +180,9 @@ module Semantic
clazz = colorize("#{exc.class}\n", color_map[:fatal])
message = colorize(exc.message.chomp(''), color_map[:error])
backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace)) # TODO: backtrace_cleaner might be optionally disable from Live::Constant
# TODO: backtrace_cleaner might be optionally disable from Live::Constant
backtrace = stackisize(Rails.backtrace_cleaner.clean(exc.backtrace))
"#{clazz}#{message}#{backtrace}"
end

Loading…
Cancel
Save