mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-09 21:26:05 +08:00
Only keep #cell: markers in stacktrace (#2351)
This commit is contained in:
parent
ca1c61c9f1
commit
56734420a0
3 changed files with 36 additions and 2 deletions
|
|
@ -334,7 +334,7 @@ defmodule Livebook.Runtime.Evaluator.Doctests do
|
|||
end
|
||||
|
||||
defp format_stacktrace_entry(entry, _test_case, _test) do
|
||||
Exception.format_stacktrace_entry(entry)
|
||||
Livebook.Runtime.Evaluator.Formatter.format_stacktrace_entry(entry)
|
||||
end
|
||||
|
||||
defp format_label(label), do: colorize(:cyan, "#{label}:")
|
||||
|
|
|
|||
|
|
@ -133,13 +133,36 @@ defmodule Livebook.Runtime.Evaluator.Formatter do
|
|||
if stacktrace == [] do
|
||||
banner
|
||||
else
|
||||
stacktrace = Exception.format_stacktrace(stacktrace)
|
||||
stacktrace = format_stacktrace(stacktrace)
|
||||
[banner, "\n", error_color(stacktrace)]
|
||||
end
|
||||
|
||||
IO.iodata_to_binary(message)
|
||||
end
|
||||
|
||||
defp format_stacktrace(trace) do
|
||||
case trace do
|
||||
[] -> "\n"
|
||||
_ -> " " <> Enum.map_join(trace, "\n ", &format_stacktrace_entry(&1)) <> "\n"
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Formats a stacktrace entry keeping only the #cell: bits.
|
||||
"""
|
||||
def format_stacktrace_entry(entry) do
|
||||
entry =
|
||||
with {mod, fun, arity, info} <- entry,
|
||||
[_ | _] = file <- info[:file],
|
||||
[_, cell] <- :string.split(file, "#cell:") do
|
||||
{mod, fun, arity, Keyword.put(info, :file, ~c"#cell:" ++ cell)}
|
||||
else
|
||||
_ -> entry
|
||||
end
|
||||
|
||||
Exception.format_stacktrace_entry(entry)
|
||||
end
|
||||
|
||||
defp blame_match(%{match?: true, node: node}), do: Macro.to_string(node)
|
||||
|
||||
defp blame_match(%{match?: false, node: node}) do
|
||||
|
|
|
|||
|
|
@ -195,6 +195,17 @@ defmodule Livebook.Runtime.EvaluatorTest do
|
|||
""" <> _ = clean_message(message)
|
||||
end
|
||||
|
||||
test "only keeps #cell: markers in stacktrace", %{evaluator: evaluator} do
|
||||
code = """
|
||||
List.first(%{})
|
||||
"""
|
||||
|
||||
Evaluator.evaluate_code(evaluator, :elixir, code, :code_1, [], file: "file.ex#cell:abcDEF")
|
||||
|
||||
assert_receive {:runtime_evaluation_response, :code_1, error(message), metadata()}
|
||||
assert message =~ " #cell:abcDEF:1: (file)"
|
||||
end
|
||||
|
||||
test "returns additional metadata when there is a syntax error", %{evaluator: evaluator} do
|
||||
code = "1+"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue