style: avoid using function-like macros in catch clauses

This commit is contained in:
Zaiming (Stone) Shi 2022-04-01 13:00:43 +02:00
parent 67608f623f
commit 850a95a43e
4 changed files with 13 additions and 13 deletions

View File

@ -662,9 +662,9 @@ end).
end
).
-define(FRAME_PARSE_ERROR(Reason), {frame_parse_error, Reason}).
-define(FRAME_SERIALIZE_ERROR(Reason), {frame_serialize_error, Reason}).
-define(THROW_FRAME_ERROR(Reason), erlang:throw(?FRAME_PARSE_ERROR(Reason))).
-define(THROW_SERIALIZE_ERROR(Reason), erlang:throw(?FRAME_SERIALIZE_ERROR(Reason))).
-define(FRAME_PARSE_ERROR, frame_parse_error).
-define(FRAME_SERIALIZE_ERROR, frame_serialize_error).
-define(THROW_FRAME_ERROR(Reason), erlang:throw({?FRAME_PARSE_ERROR, Reason})).
-define(THROW_SERIALIZE_ERROR(Reason), erlang:throw({?FRAME_SERIALIZE_ERROR, Reason})).
-endif.

View File

@ -765,7 +765,7 @@ parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
NState = State#state{parse_state = NParseState},
parse_incoming(Rest, [Packet | Packets], NState)
catch
throw:?FRAME_PARSE_ERROR(Reason) ->
throw:{?FRAME_PARSE_ERROR, Reason} ->
?SLOG(info, #{
reason => Reason,
at_state => emqx_frame:describe_state(ParseState),
@ -840,19 +840,19 @@ serialize_and_inc_stats_fun(#state{serialize = Serialize}) ->
Data
catch
%% Maybe Never happen.
throw:?FRAME_SERIALIZE_ERROR(Reason) ->
throw:{?FRAME_SERIALIZE_ERROR, Reason} ->
?SLOG(info, #{
reason => Reason,
input_packet => Packet
}),
erlang:error(?FRAME_SERIALIZE_ERROR(Reason));
erlang:error({?FRAME_SERIALIZE_ERROR, Reason});
error:Reason:Stacktrace ->
?SLOG(error, #{
input_packet => Packet,
exception => Reason,
stacktrace => Stacktrace
}),
erlang:error(frame_serialize_error)
erlang:error(?FRAME_SERIALIZE_ERROR)
end
end.

View File

@ -676,7 +676,7 @@ parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
NState = State#state{parse_state = NParseState},
parse_incoming(Rest, [{incoming, Packet} | Packets], NState)
catch
throw:?FRAME_PARSE_ERROR(Reason) ->
throw:{?FRAME_PARSE_ERROR, Reason} ->
?SLOG(info, #{
reason => Reason,
at_state => emqx_frame:describe_state(ParseState),
@ -791,19 +791,19 @@ serialize_and_inc_stats_fun(#state{serialize = Serialize}) ->
Data
catch
%% Maybe Never happen.
throw:?FRAME_SERIALIZE_ERROR(Reason) ->
throw:{?FRAME_SERIALIZE_ERROR, Reason} ->
?SLOG(info, #{
reason => Reason,
input_packet => Packet
}),
erlang:error(?FRAME_SERIALIZE_ERROR(Reason));
erlang:error({?FRAME_SERIALIZE_ERROR, Reason});
error:Reason:Stacktrace ->
?SLOG(error, #{
input_packet => Packet,
exception => Reason,
stacktrace => Stacktrace
}),
erlang:error(frame_serialize_error)
erlang:error(?FRAME_SERIALIZE_ERROR)
end
end.

View File

@ -24,7 +24,7 @@
-include_lib("common_test/include/ct.hrl").
-define(ASSERT_FRAME_THROW(Reason, Expr),
?assertThrow(?FRAME_PARSE_ERROR(Reason), Expr)
?assertThrow({?FRAME_PARSE_ERROR, Reason}, Expr)
).
all() ->