Skip to content

Commit 62d9204

Browse files
author
Simon MacMullen
committed
Still nicer error handling inspired by lib:eval_str/1.
1 parent 5af438f commit 62d9204

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/rabbit_control.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ start() ->
9898
{error, Reason} ->
9999
print_error("~p", [Reason]),
100100
rabbit_misc:quit(2);
101+
{error_string, Reason} ->
102+
print_error("~s", [Reason]),
103+
rabbit_misc:quit(2);
101104
{badrpc, {'EXIT', Reason}} ->
102105
print_error("~p", [Reason]),
103106
rabbit_misc:quit(2);
@@ -379,11 +382,11 @@ action(eval, Node, [Expr], _Opts, _Inform) ->
379382
Node, erl_eval, exprs, [Parsed, []]),
380383
io:format("~p~n", [Value]),
381384
ok;
382-
{error, {1, erl_parse, Err}} ->
383-
{error, Err}
385+
{error, E} ->
386+
{error_string, format_parse_error(E)}
384387
end;
385-
{error, {1, erl_scan, E}, _} ->
386-
{error, ["scan error: ", E]}
388+
{error, E, _} ->
389+
{error_string, format_parse_error(E)}
387390
end.
388391

389392
%%----------------------------------------------------------------------------
@@ -459,6 +462,9 @@ system(Cmd) ->
459462
escape_quotes(Cmd) ->
460463
lists:flatten(lists:map(fun ($') -> "'\\''"; (Ch) -> Ch end, Cmd)).
461464

465+
format_parse_error({_Line, Mod, Err}) ->
466+
lists:flatten(Mod:format_error(Err)).
467+
462468
%%----------------------------------------------------------------------------
463469

464470
default_if_empty(List, Default) when is_list(List) ->

0 commit comments

Comments
 (0)