From 760ef9210a76de98efb21980616168ad7ba4fdf3 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Wed, 4 Nov 2020 13:07:42 +0100 Subject: [PATCH] fix(stomp): Fix dialyzer warnings --- apps/emqx_stomp/include/emqx_stomp.hrl | 2 +- apps/emqx_stomp/src/emqx_stomp_frame.erl | 6 +++++- apps/emqx_stomp/src/emqx_stomp_protocol.erl | 19 +++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/apps/emqx_stomp/include/emqx_stomp.hrl b/apps/emqx_stomp/include/emqx_stomp.hrl index 504191110..e2eeee7d8 100644 --- a/apps/emqx_stomp/include/emqx_stomp.hrl +++ b/apps/emqx_stomp/include/emqx_stomp.hrl @@ -24,7 +24,7 @@ %% STOMP Frame %%-------------------------------------------------------------------- --record(stomp_frame, {command, headers = [], body = <<>> :: iolist()}). +-record(stomp_frame, {command, headers = [], body = <<>> :: iodata()}). -type(stomp_frame() :: #stomp_frame{}). diff --git a/apps/emqx_stomp/src/emqx_stomp_frame.erl b/apps/emqx_stomp/src/emqx_stomp_frame.erl index e5795335a..20bbf513d 100644 --- a/apps/emqx_stomp/src/emqx_stomp_frame.erl +++ b/apps/emqx_stomp/src/emqx_stomp_frame.erl @@ -87,7 +87,11 @@ -define(IS_ESC(Ch), Ch == ?CR; Ch == ?LF; Ch == ?BSL; Ch == ?COLON). --record(parser_state, {cmd, headers = [], hdname, acc = <<>>, limit}). +-record(parser_state, {cmd, + headers = [], + hdname, + acc = <<>> :: binary(), + limit}). -record(frame_limit, {max_header_num, max_header_length, max_body_length}). diff --git a/apps/emqx_stomp/src/emqx_stomp_protocol.erl b/apps/emqx_stomp/src/emqx_stomp_protocol.erl index fa75f08e3..ff49cd381 100644 --- a/apps/emqx_stomp/src/emqx_stomp_protocol.erl +++ b/apps/emqx_stomp/src/emqx_stomp_protocol.erl @@ -99,12 +99,12 @@ received(#stomp_frame{command = <<"CONNECT">>, headers = Headers}, send(connected_frame([{<<"version">>, Version}, {<<"heart-beat">>, reverse_heartbeats(Heartbeats)}]), NewState); false -> - send(error_frame(undefined, <<"Login or passcode error!">>), State), + _ = send(error_frame(undefined, <<"Login or passcode error!">>), State), {error, login_or_passcode_error, State} end; {error, Msg} -> - send(error_frame([{<<"version">>, <<"1.0,1.1,1.2">>}, - {<<"content-type">>, <<"text/plain">>}], undefined, Msg), State), + _ = send(error_frame([{<<"version">>, <<"1.0,1.1,1.2">>}, + {<<"content-type">>, <<"text/plain">>}], undefined, Msg), State), {error, unsupported_version, State} end; @@ -114,10 +114,9 @@ received(#stomp_frame{command = <<"CONNECT">>}, State = #stomp_proto{connected = received(#stomp_frame{command = <<"SEND">>, headers = Headers, body = Body}, State) -> Topic = header(<<"destination">>, Headers), Action = fun(State0) -> - maybe_send_receipt(receipt_id(Headers), State0), - emqx_broker:publish( - make_mqtt_message(Topic, Headers, iolist_to_binary(Body)) - ), + _ = maybe_send_receipt(receipt_id(Headers), State0), + _ = emqx_broker:publish( + make_mqtt_message(Topic, Headers, iolist_to_binary(Body))), State0 end, case header(<<"transaction">>, Headers) of @@ -160,7 +159,7 @@ received(#stomp_frame{command = <<"UNSUBSCRIBE">>, headers = Headers}, received(#stomp_frame{command = <<"ACK">>, headers = Headers}, State) -> Id = header(<<"id">>, Headers), Action = fun(State0) -> - maybe_send_receipt(receipt_id(Headers), State0), + _ = maybe_send_receipt(receipt_id(Headers), State0), ack(Id, State0) end, case header(<<"transaction">>, Headers) of @@ -176,7 +175,7 @@ received(#stomp_frame{command = <<"ACK">>, headers = Headers}, State) -> received(#stomp_frame{command = <<"NACK">>, headers = Headers}, State) -> Id = header(<<"id">>, Headers), Action = fun(State0) -> - maybe_send_receipt(receipt_id(Headers), State0), + _ = maybe_send_receipt(receipt_id(Headers), State0), nack(Id, State0) end, case header(<<"transaction">>, Headers) of @@ -226,7 +225,7 @@ received(#stomp_frame{command = <<"ABORT">>, headers = Headers}, State) -> end; received(#stomp_frame{command = <<"DISCONNECT">>, headers = Headers}, State) -> - maybe_send_receipt(receipt_id(Headers), State), + _ = maybe_send_receipt(receipt_id(Headers), State), {stop, normal, State}. send(Msg = #message{topic = Topic, headers = Headers, payload = Payload},