style: avoid using function-like macros in catch clauses
This commit is contained in:
parent
67608f623f
commit
850a95a43e
|
@ -662,9 +662,9 @@ end).
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
-define(FRAME_PARSE_ERROR(Reason), {frame_parse_error, Reason}).
|
-define(FRAME_PARSE_ERROR, frame_parse_error).
|
||||||
-define(FRAME_SERIALIZE_ERROR(Reason), {frame_serialize_error, Reason}).
|
-define(FRAME_SERIALIZE_ERROR, frame_serialize_error).
|
||||||
-define(THROW_FRAME_ERROR(Reason), erlang:throw(?FRAME_PARSE_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(THROW_SERIALIZE_ERROR(Reason), erlang:throw({?FRAME_SERIALIZE_ERROR, Reason})).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
|
@ -765,7 +765,7 @@ parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
|
||||||
NState = State#state{parse_state = NParseState},
|
NState = State#state{parse_state = NParseState},
|
||||||
parse_incoming(Rest, [Packet | Packets], NState)
|
parse_incoming(Rest, [Packet | Packets], NState)
|
||||||
catch
|
catch
|
||||||
throw:?FRAME_PARSE_ERROR(Reason) ->
|
throw:{?FRAME_PARSE_ERROR, Reason} ->
|
||||||
?SLOG(info, #{
|
?SLOG(info, #{
|
||||||
reason => Reason,
|
reason => Reason,
|
||||||
at_state => emqx_frame:describe_state(ParseState),
|
at_state => emqx_frame:describe_state(ParseState),
|
||||||
|
@ -840,19 +840,19 @@ serialize_and_inc_stats_fun(#state{serialize = Serialize}) ->
|
||||||
Data
|
Data
|
||||||
catch
|
catch
|
||||||
%% Maybe Never happen.
|
%% Maybe Never happen.
|
||||||
throw:?FRAME_SERIALIZE_ERROR(Reason) ->
|
throw:{?FRAME_SERIALIZE_ERROR, Reason} ->
|
||||||
?SLOG(info, #{
|
?SLOG(info, #{
|
||||||
reason => Reason,
|
reason => Reason,
|
||||||
input_packet => Packet
|
input_packet => Packet
|
||||||
}),
|
}),
|
||||||
erlang:error(?FRAME_SERIALIZE_ERROR(Reason));
|
erlang:error({?FRAME_SERIALIZE_ERROR, Reason});
|
||||||
error:Reason:Stacktrace ->
|
error:Reason:Stacktrace ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
input_packet => Packet,
|
input_packet => Packet,
|
||||||
exception => Reason,
|
exception => Reason,
|
||||||
stacktrace => Stacktrace
|
stacktrace => Stacktrace
|
||||||
}),
|
}),
|
||||||
erlang:error(frame_serialize_error)
|
erlang:error(?FRAME_SERIALIZE_ERROR)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -676,7 +676,7 @@ parse_incoming(Data, Packets, State = #state{parse_state = ParseState}) ->
|
||||||
NState = State#state{parse_state = NParseState},
|
NState = State#state{parse_state = NParseState},
|
||||||
parse_incoming(Rest, [{incoming, Packet} | Packets], NState)
|
parse_incoming(Rest, [{incoming, Packet} | Packets], NState)
|
||||||
catch
|
catch
|
||||||
throw:?FRAME_PARSE_ERROR(Reason) ->
|
throw:{?FRAME_PARSE_ERROR, Reason} ->
|
||||||
?SLOG(info, #{
|
?SLOG(info, #{
|
||||||
reason => Reason,
|
reason => Reason,
|
||||||
at_state => emqx_frame:describe_state(ParseState),
|
at_state => emqx_frame:describe_state(ParseState),
|
||||||
|
@ -791,19 +791,19 @@ serialize_and_inc_stats_fun(#state{serialize = Serialize}) ->
|
||||||
Data
|
Data
|
||||||
catch
|
catch
|
||||||
%% Maybe Never happen.
|
%% Maybe Never happen.
|
||||||
throw:?FRAME_SERIALIZE_ERROR(Reason) ->
|
throw:{?FRAME_SERIALIZE_ERROR, Reason} ->
|
||||||
?SLOG(info, #{
|
?SLOG(info, #{
|
||||||
reason => Reason,
|
reason => Reason,
|
||||||
input_packet => Packet
|
input_packet => Packet
|
||||||
}),
|
}),
|
||||||
erlang:error(?FRAME_SERIALIZE_ERROR(Reason));
|
erlang:error({?FRAME_SERIALIZE_ERROR, Reason});
|
||||||
error:Reason:Stacktrace ->
|
error:Reason:Stacktrace ->
|
||||||
?SLOG(error, #{
|
?SLOG(error, #{
|
||||||
input_packet => Packet,
|
input_packet => Packet,
|
||||||
exception => Reason,
|
exception => Reason,
|
||||||
stacktrace => Stacktrace
|
stacktrace => Stacktrace
|
||||||
}),
|
}),
|
||||||
erlang:error(frame_serialize_error)
|
erlang:error(?FRAME_SERIALIZE_ERROR)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
-define(ASSERT_FRAME_THROW(Reason, Expr),
|
-define(ASSERT_FRAME_THROW(Reason, Expr),
|
||||||
?assertThrow(?FRAME_PARSE_ERROR(Reason), Expr)
|
?assertThrow({?FRAME_PARSE_ERROR, Reason}, Expr)
|
||||||
).
|
).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
|
|
Loading…
Reference in New Issue