Module: Trailblazer::Developer::Wtf
- Defined in:
- lib/trailblazer/developer/wtf.rb,
lib/trailblazer/developer/wtf/renderer.rb
Defined Under Namespace
Class Method Summary collapse
-
.invoke(activity, ctx, flow_options, present_options: {}, **circuit_options) ⇒ Object
Run activity with tracing enabled and inject a mutable Stack instance.
Class Method Details
.invoke(activity, ctx, flow_options, present_options: {}, **circuit_options) ⇒ Object
Run activity with tracing enabled and inject a mutable Stack instance. This allows to display the trace even when an exception happened
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/trailblazer/developer/wtf.rb', line 17 def invoke(activity, (ctx, ), present_options: {}, **) ||= {} = ->(*) { {} } stack = Trace::Stack.new # unfortunately, we need this mutable object before things break. raise_exception = false begin complete_stack, signal, (ctx, ) = Trace.invoke( activity, [ctx, .merge(stack: stack)], ** ) rescue raise_exception = $! # TODO: will this show the very same stacktrace? exception_source = Exception.find_exception_source(stack, $!) complete_stack = stack = ->(trace_nodes:, **) { exception_source_node = trace_nodes.reverse.find do |trace_node| trace_node.snapshot_after == exception_source || trace_node.snapshot_before == exception_source end { # we can hand in options per node, identified by their captured_input part. node_options: { exception_source_node => {data: {exception_source: true}}, # goes to {Debugger::Node.build} }, style: { exception_source_node => [:red, :bold] }, } } end # always render the trace. output, returned_args = Trace::Present.( complete_stack, renderer: Wtf::Renderer, color_map: Wtf::Renderer::DEFAULT_COLOR_MAP.merge([:color_map] || {}), activity: activity, **, & ) puts output raise raise_exception if raise_exception return signal, [ctx, ], , output, returned_args end |