Class: ConvenientService::Service::Plugins::RescuesResultUnhandledExceptions::Commands::FormatException

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ConvenientService::Support::Command

[], call

Constructor Details

#initialize(exception:, args:, kwargs:, block:, max_backtrace_size: Constants::DEFAULT_MAX_BACKTRACE_SIZE) ⇒ void

Parameters:

  • exception (StandardError)
  • args (Array<Object>)
  • kwargs (Hash{Symbol => Object})
  • block (Proc, nil)
  • max_backtrace_size (Integer) (defaults to: Constants::DEFAULT_MAX_BACKTRACE_SIZE)


47
48
49
50
51
52
53
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb', line 47

def initialize(exception:, args:, kwargs:, block:, max_backtrace_size: Constants::DEFAULT_MAX_BACKTRACE_SIZE)
  @exception = exception
  @args = args
  @kwargs = kwargs
  @block = block
  @max_backtrace_size = max_backtrace_size
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



25
26
27
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb', line 25

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



37
38
39
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb', line 37

def block
  @block
end

#exceptionObject (readonly)

Returns the value of attribute exception.



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

def exception
  @exception
end

#kwargsObject (readonly)

Returns the value of attribute kwargs.



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

def kwargs
  @kwargs
end

#max_backtrace_sizeObject (readonly)

Returns the value of attribute max_backtrace_size.



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

def max_backtrace_size
  @max_backtrace_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:

Simple exception.


StandardError:
  exception message
# /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_callers.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.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'

Exception with multiline message.


StandardError:
  exception message first line
  exception message second line
  exception message third line
# /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_callers.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.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'

Exception with backtrace with more than 10 lines.


StandardError:
  exception message
# /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_callers.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.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'
# ...

Exception with cause.


StandardError:
  exception message
# /gem/lib/convenient_service/factories/service/class.rb:43:in `rescue in result'
# /gem/lib/convenient_service/factories/service/class.rb:40:in `result'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.rb:116:in `call'
# /gem/lib/convenient_service/core/entities/config/entities/method_middlewares/entities/caller/commands/define_method_callers.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'
------------------
--- Caused by: ---
StandardError:
  cause message
# /gem/lib/convenient_service/factories/service/class.rb:41:in `result'

Returns:

  • (String)


133
134
135
136
137
138
139
140
# File 'lib/convenient_service/service/plugins/rescues_result_unhandled_exceptions/commands/format_exception.rb', line 133

def call
  <<~MESSAGE.rstrip
    #{formatted_exception_class}
    #{formatted_exception_message}
    #{formatted_exception_backtrace}
    #{formatted_exception_cause}
  MESSAGE
end