Class: ConvenientService::Service::Plugins::RescuesResultUnhandledExceptions::Commands::FormatBacktrace

Inherits:
ConvenientService::Support::Command show all
Defined in:
lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConvenientService::Support::Command

[], call

Constructor Details

#initialize(backtrace:, max_size: Constants::DEFAULT_MAX_BACKTRACE_SIZE) ⇒ void

Parameters:

  • backtrace (Array, nil)
  • max_size (Integer) (defaults to: Constants::DEFAULT_MAX_BACKTRACE_SIZE)


31
32
33
34
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb', line 31

def initialize(backtrace:, max_size: Constants::DEFAULT_MAX_BACKTRACE_SIZE)
  @backtrace = backtrace.to_a
  @max_size = max_size
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



13
14
15
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb', line 13

def backtrace
  @backtrace
end

#max_sizeObject (readonly)

Returns the value of attribute max_size.



19
20
21
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb', line 19

def max_size
  @max_size
end

Instance Method Details

#callString

Note:

Exceptions formatting is inspired by RSpec. It has almost the same output (at least for RSpec 3).

Examples:

Backtrace with upto 10 lines.


# /gem/lib/convenient_service/factories/services.rb:120:in `result'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb:116:in `block in result'
# /gem/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb:67:in `block (2 levels) in build_call_chain'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb:35:in `next'
# /gem/lib/convenient_service/common/plugins/caches_return_value/middleware.rb:17:in `block in next'
# /gem/lib/convenient_service/support/cache.rb:110:in `fetch'
# /gem/lib/convenient_service/common/plugins/caches_return_value/middleware.rb:17:in `next'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb:73:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb:35:in `next'

Backtrace with more than 10 lines.


# /gem/lib/convenient_service/factories/services.rb:120:in `result'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_middlewares_caller.rb:116:in `block in result'
# /gem/lib/convenient_service/dependencies/extractions/ruby_middleware/middleware/runner.rb:67:in `block (2 levels) in build_call_chain'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb:35:in `next'
# /gem/lib/convenient_service/common/plugins/caches_return_value/middleware.rb:17:in `block in next'
# /gem/lib/convenient_service/support/cache.rb:110:in `fetch'
# /gem/lib/convenient_service/common/plugins/caches_return_value/middleware.rb:17:in `next'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/middleware.rb:73:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/chain.rb:35:in `next'
# ...

Returns:

  • (String)


68
69
70
71
72
73
74
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_backtrace.rb', line 68

def call
  message = backtrace.take(max_size).map { |line| Commands::FormatLine.call(line: line) }.join("\n")

  message << "\n# ..." if backtrace.size > max_size

  message
end