Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/elixir/lib/kernel/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ defmodule Kernel.CLI do
Shared helper for error formatting on CLI tools.
"""
def format_error(kind, reason, stacktrace) do
{banner, rest} = format_error_parts(kind, reason, stacktrace)
[banner, rest]
end

defp format_error_parts(kind, reason, stacktrace) do
{blamed, stacktrace} = Exception.blame(kind, reason, stacktrace)

iodata =
banner =
case blamed do
%FunctionClauseError{} ->
formatted = Exception.format_banner(kind, reason, stacktrace)
Expand All @@ -112,7 +117,7 @@ defmodule Kernel.CLI do
Exception.format_banner(kind, blamed, stacktrace)
end

[iodata, ?\n, Exception.format_stacktrace(prune_stacktrace(stacktrace))]
{banner, [?\n, Exception.format_stacktrace(prune_stacktrace(stacktrace))]}
end

@doc """
Expand Down Expand Up @@ -179,7 +184,8 @@ defmodule Kernel.CLI do
## Error handling

defp print_error(kind, reason, stacktrace) do
IO.write(:stderr, format_error(kind, reason, stacktrace))
{banner, rest} = format_error_parts(kind, reason, stacktrace)
IO.write(:stderr, [IO.ANSI.format([:red, banner]), rest])
end

defp blame_match(%{match?: true, node: node}), do: blame_ansi(:normal, "+", node)
Expand Down
Loading