Class: ConvenientService::Support::BacktraceCleaner
- Inherits:
-
Dependencies::Extractions::ActiveSupportBacktraceCleaner::BacktraceCleaner
- Object
- Dependencies::Extractions::ActiveSupportBacktraceCleaner::BacktraceCleaner
- ConvenientService::Support::BacktraceCleaner
- Defined in:
- lib/convenient_service/support/backtrace_cleaner.rb
Overview
Rails v7.1.2 Backtrace Cleaner descendant.
Has Convenient Service specific silencer - add_convenient_service_silencer
.
By default, it uses only add_stdlib_silencer
and add_convenient_service_silencer
.
Instance Method Summary collapse
-
#add_convenient_service_silencer ⇒ void
Since Convenient Service is using middleware chains under the hood, exception backtraces may be huge.
-
#clean(backtrace, *args) ⇒ Array<String>
Works exactly in the same way as the original
clean
, except it falls back to the original backtrace in case of any exceptions inside filters or silencers. - #initialize ⇒ void constructor
Methods inherited from Dependencies::Extractions::ActiveSupportBacktraceCleaner::BacktraceCleaner
#add_filter, #add_silencer, #clean_frame, #remove_filters!, #remove_silencers!
Constructor Details
#initialize ⇒ void
ConvenientService::Support::BacktraceCleaner
intentionally does NOT exclude external gems lines from backtrace.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/convenient_service/support/backtrace_cleaner.rb', line 34 def initialize(...) super remove_filters! remove_silencers! ## # NOTE: Uses `::RbConfig` to resolve stdlib directory. # - https://idiosyncratic-ruby.com/42-ruby-config.html # - https://github.com/ruby/ruby/blob/master/tool/mkconfig.rb # add_stdlib_silencer ## # NOTE: # add_convenient_service_silencer end |
Instance Method Details
#add_convenient_service_silencer ⇒ void
To bring back Convenient Service lines to backtraces, use the remove_silencers
or check the CleansExceptionBacktrace
plugin.
This method returns an undefined value.
Since Convenient Service is using middleware chains under the hood, exception backtraces may be huge. As a consequence, it takes too much time during the debugging process to find the application line of code that causes the exception. This silencer removes all Convenient Service lines from backtraces.
89 90 91 92 93 94 95 96 |
# File 'lib/convenient_service/support/backtrace_cleaner.rb', line 89 def add_convenient_service_silencer add_silencer do |line| next false if line.start_with?(::ConvenientService.examples_root.to_s) next false if line.start_with?(::ConvenientService.spec_root.to_s) line.start_with?(::ConvenientService.root.to_s) end end |
#clean(backtrace, *args) ⇒ Array<String>
Works exactly in the same way as the original clean
, except it falls back to the original backtrace in case of any exceptions inside filters or silencers.
Also returns an empty array, when backtrace
is nil
.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/convenient_service/support/backtrace_cleaner.rb', line 111 def clean(backtrace, *args) if backtrace.nil? ::ConvenientService.logger.warn { "[BacktraceCleaner] `nil` backtrace | Empty array is used as fallback" } return [] end begin super rescue ::ConvenientService.logger.warn { "[BacktraceCleaner] Some filter or silencer is broken | Original backtrace is used as fallback" } backtrace end end |