Skip to content

Commit

Permalink
in #wtf, we now print the trace and show the Push exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed May 30, 2024
1 parent d0da994 commit f27e372
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
33 changes: 21 additions & 12 deletions lib/trailblazer/pro/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ module Debugger
module_function

# Called in {Trace::Present.call} as {:render_method}.
def call(debugger_trace:, activity:, render_wtf: false, renderer:, **options)
trace_data = render_trace_data(debugger_trace, activity: activity, **options)
# This method always returns [output, *], where {output}
# is an arbitrary string to be written to the logger or CLI.
def call(activity:, render_wtf: false, **options)
output = ""

trace_data = render_trace_data(activity: activity, **options)

trace_envelope = {
fields: {
Expand All @@ -17,30 +21,28 @@ def call(debugger_trace:, activity:, render_wtf: false, renderer:, **options)

session, stored_trace_id, session_updated = push(trace_envelope, activity: activity, **options)

if render_wtf
output += render_original_wtf_trace(**options)
end

# This block covers when something in {push} above went wrong.
if session.nil?
output = stored_trace_id
output += stored_trace_id
return output, []
end

debugger_url = "https://ide.trailblazer.to/#{stored_trace_id}"
# output = "[TRB PRO] view trace (#{activity}) at #{debugger_url}"
# output = Developer::Wtf::Renderer::String.bold(output)
output = Developer::Wtf::Renderer::String.bold("[TRB PRO] view trace (#{activity}) at ")
output += Developer::Wtf::Renderer::String.bold("[TRB PRO] view trace (#{activity}) at ")
output += debugger_url # DISCUSS: what do we want bold here?

if render_wtf
# TODO: take the color_map from outside caller.
wtf_output = Developer::Trace::Present.render(debugger_trace: debugger_trace, renderer: renderer, color_map: Developer::Wtf::Renderer::DEFAULT_COLOR_MAP) # , activity: activity

output = [wtf_output, output].join("\n")
end

returned_values = [session, stored_trace_id, debugger_url, trace_envelope, session_updated]

return output, returned_values
end

def render_trace_data(debugger_trace, activity:, **)
def render_trace_data(debugger_trace:, activity:, **)
flat_tree_json = debugger_trace.to_a.collect do |debugger_node|

# TODO: do we even need to grab tw by path here?
Expand Down Expand Up @@ -72,6 +74,13 @@ def render_trace_data(debugger_trace, activity:, **)
)
end

def render_original_wtf_trace(debugger_trace:, renderer:, color_map: Developer::Wtf::Renderer::DEFAULT_COLOR_MAP, **)
# TODO: take the color_map from outside caller.
wtf_output = Developer::Trace::Present.render(debugger_trace: debugger_trace, renderer: renderer, color_map: Developer::Wtf::Renderer::DEFAULT_COLOR_MAP) # , activity: activity

output = [wtf_output, output].join("\n")
end

class Push < Trailblazer::Activity::Railway
step Subprocess(Client::Connect), # TODO: assert that success/failure go to right Track.
Output(:failure) => Track(:failure),
Expand Down
6 changes: 5 additions & 1 deletion test/wtf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def model(ctx, **)

signal, (ctx, _), _, output, (session, trace_id, debugger_url, _trace_envelope) = Trailblazer::Pro::Trace::Wtf.call(Create, [{}, {}])

assert_equal output, %(Custom token couldn't be retrieved. HTTP status: 401)
assert_equal output, %(WtfTest::Create
|-- \e[32mStart.default\e[0m
|-- \e[32mmodel\e[0m
`-- End.success
Custom token couldn't be retrieved. HTTP status: 401)
end
end

0 comments on commit f27e372

Please sign in to comment.