style: avoid using function-like macros in catch clauses
This commit is contained in:
parent
67608f623f
commit
850a95a43e
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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() ->
|
||||
|
|
Loading…
Reference in New Issue