Skip to content

Commit

Permalink
Fixing dialyzer and removing square brackets around jiffy:encode used…
Browse files Browse the repository at this point in the history
… for locating lines that need changes.
  • Loading branch information
JanuszJakubiec committed Dec 11, 2024
1 parent d0a1572 commit d603ba0
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 74 deletions.
3 changes: 1 addition & 2 deletions src/ejabberd_ctl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ handle_graphql_result({ok, Result}) ->
end;
handle_graphql_result({error, Reason}) ->
{_Code, Error} = mongoose_graphql_errors:format_error(Reason),
%CHANGED
JSONResult = [jiffy:encode(#{errors => [Error]}, [pretty])],
JSONResult = jiffy:encode(#{errors => [Error]}, [pretty]),
?PRINT("~s\n", [JSONResult]),
?STATUS_ERROR.

Expand Down
4 changes: 2 additions & 2 deletions src/event_pusher/mod_event_pusher_push_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ decode_row({NodeID, PubSubBin, FormJSON}) ->
NodeID,
decode_form(FormJSON)}.

-spec encode_form(mod_event_pusher_push:form()) -> iodata().
encode_form(Form) ->
%CHANGED
[jiffy:encode(Form)].
jiffy:encode(Form).

decode_form(FormJSON) ->
jiffy:decode(FormJSON, [return_maps]).
Expand Down
3 changes: 1 addition & 2 deletions src/graphql/mongoose_graphql_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ make_error(Phase, Term) ->

reply_error(Msg, Req, State) ->
{Code, Error} = mongoose_graphql_errors:format_error(Msg),
%CHANGED
Body = [jiffy:encode(#{errors => [Error]})],
Body = jiffy:encode(#{errors => [Error]}),
Req2 = cowboy_req:set_resp_body(Body, Req),
Reply = cowboy_req:reply(Code, Req2),
{stop, Reply, State}.
Expand Down
3 changes: 1 addition & 2 deletions src/graphql/mongoose_graphql_sse_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,5 @@ make_error(Phase, Term) ->

reply_error(Reason, Req, State) ->
{Code, Error} = mongoose_graphql_errors:format_error(Reason),
%CHANGED
Body = [jiffy:encode(#{errors => [Error]})],
Body = jiffy:encode(#{errors => [Error]}),
{shutdown, Code, #{}, Body, Req, State}.
3 changes: 1 addition & 2 deletions src/mod_caps_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ read(HostType, {Node, SubNode}) ->
-spec write(mongooseim:host_type(), mod_caps:node_pair(),
mod_caps:maybe_pending_features()) -> ok.
write(HostType, {Node, SubNode}, Features) ->
%CHANGED
Encoded = [jiffy:encode(Features)],
Encoded = jiffy:encode(Features),
InsertParams = [Node, SubNode, Encoded],
UpdateParams = [Encoded],
UniqueKeyValues = [Node, SubNode],
Expand Down
3 changes: 1 addition & 2 deletions src/mod_push_service_mongoosepush.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ push_notifications(AccIn,
ReqHeaders = [{<<"content-type">>, <<"application/json">>}],
{ok, JSON} =
make_notification(Notification, Options),
%CHANGED
Payload = [jiffy:encode(JSON)],
Payload = jiffy:encode(JSON),
call(Host, ?MODULE, http_notification, [Host, post, Path, ReqHeaders, Payload])
end,
{ok, send_push_notifications(Notifications, Fun, ok)}.
Expand Down
6 changes: 2 additions & 4 deletions src/mongoose_admin_api/mongoose_admin_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ resource_created(Req, State, Path, Body) ->
%% @doc Send response when it can't be returned in a tuple from the handler (e.g. for DELETE)
-spec respond(req(), state(), jiffy:json_value()) -> {stop, req(), state()}.
respond(Req, State, Response) ->
%CHANGED
Req2 = cowboy_req:set_resp_body([jiffy:encode(Response)], Req),
Req2 = cowboy_req:set_resp_body(jiffy:encode(Response), Req),
Req3 = cowboy_req:reply(200, Req2),
{stop, Req3, State}.

Expand All @@ -151,8 +150,7 @@ error_response(ErrorType, Message, Req, State) ->
error_type => ErrorType,
message => BinMessage,
req => Req}),
%CHANGED
Req1 = cowboy_req:reply(error_code(ErrorType), #{}, [jiffy:encode(BinMessage)], Req),
Req1 = cowboy_req:reply(error_code(ErrorType), #{}, jiffy:encode(BinMessage), Req),
{stop, Req1, State}.

-spec error_code(error_type()) -> non_neg_integer().
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_admin_api/mongoose_admin_api_contacts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ handle_get(Req, State) ->
UserJid = get_user_jid(Bindings),
case mod_roster_api:list_contacts(UserJid) of
{ok, Rosters} ->
%CHANGED
{[jiffy:encode(lists:map(fun roster_info/1, Rosters))], Req, State};
{jiffy:encode(lists:map(fun roster_info/1, Rosters)), Req, State};
{unknown_domain, Reason} ->
throw_error(not_found, Reason)
end.
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_admin_api/mongoose_admin_api_domain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ handle_get(Req, State) ->
Domain = get_domain(Bindings),
case mongoose_domain_api:get_domain_details(Domain) of
{ok, Props} ->
%CHANGED
{[jiffy:encode(maps:with([host_type, status], Props))], Req, State};
{jiffy:encode(maps:with([host_type, status], Props)), Req, State};
{not_found, Msg} ->
throw_error(not_found, Msg);
{_, Msg} ->
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_admin_api/mongoose_admin_api_messages.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ handle_get(Req, State) ->
case mongoose_stanza_api:lookup_recent_messages(OwnerJid, WithJid, Before, Limit, true) of
{ok, {Rows, _Limit}} ->
Messages = lists:map(fun row_to_map/1, Rows),
%CHANGED
{[jiffy:encode(Messages)], Req, State};
{jiffy:encode(Messages), Req, State};
{unknown_user, Msg} ->
throw_error(bad_request, Msg)
end.
Expand Down
12 changes: 4 additions & 8 deletions src/mongoose_admin_api/mongoose_admin_api_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ handle_get(Req, State = #{suffix := all}) ->
end;
all_metrics ->
Values = get_sum_metrics(),
%CHANGED
{[jiffy:encode(#{metrics => Values})], Req, State}
{jiffy:encode(#{metrics => Values}), Req, State}
end;
handle_get(Req, State = #{suffix := global}) ->
Bindings = cowboy_req:bindings(Req),
Expand All @@ -81,17 +80,15 @@ handle_get(Req, State) ->
Reply = #{host_types => HostTypes,
metrics => lists:map(fun prepare_name/1, Metrics),
global => lists:map(fun prepare_name/1, Global)},
%CHANGED
{[jiffy:encode(Reply)], Req, State}
{jiffy:encode(Reply), Req, State}
end.

handle_get_values(Req, State, Bindings, HostType) ->
case get_metric_name(Bindings) of
{metric, Metric} ->
case mongoose_instrument_exometer:get_metric_value(HostType, Metric) of
{ok, Value} ->
%CHANGED
{[jiffy:encode(#{metric => prepare_value(Value)})], Req, State};
{jiffy:encode(#{metric => prepare_value(Value)}), Req, State};
_Other ->
throw_error(not_found, <<"Metric not found">>)
end;
Expand All @@ -101,8 +98,7 @@ handle_get_values(Req, State, Bindings, HostType) ->
throw_error(not_found, <<"No metrics found">>);
Metrics ->
Values = prepare_metrics(Metrics),
%CHANGED
{[jiffy:encode(#{metrics => Values})], Req, State}
{jiffy:encode(#{metrics => Values}), Req, State}
end
end.

Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_admin_api/mongoose_admin_api_sessions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ delete_resource(Req, State) ->
handle_get(Req, State) ->
#{domain := Domain} = cowboy_req:bindings(Req),
{ok, Sessions} = mongoose_session_api:list_resources(Domain),
%CHANGED
{[jiffy:encode(Sessions)], Req, State}.
{jiffy:encode(Sessions), Req, State}.

handle_delete(Req, State) ->
#{domain := Domain} = Bindings = cowboy_req:bindings(Req),
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_admin_api/mongoose_admin_api_users.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ handle_get(Req, State) ->
#{domain := Domain} = cowboy_req:bindings(Req),
Users = mongoose_account_api:list_users(Domain),
{_, UsersList} = Users,
%CHANGED
{[jiffy:encode(UsersList)], Req, State}.
{jiffy:encode(UsersList), Req, State}.

handle_post(Req, State) ->
#{domain := Domain} = cowboy_req:bindings(Req),
Expand Down
3 changes: 1 addition & 2 deletions src/mongoose_client_api/mongoose_client_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ error_response(ErrorType, Message, Req, State) ->
error_type => ErrorType,
message => BinMessage,
req => Req}),
%CHANGED
Req1 = cowboy_req:reply(error_code(ErrorType), #{}, [jiffy:encode(BinMessage)], Req),
Req1 = cowboy_req:reply(error_code(ErrorType), #{}, jiffy:encode(BinMessage), Req),
{stop, Req1, State}.

-spec error_code(error_type()) -> non_neg_integer().
Expand Down
6 changes: 2 additions & 4 deletions src/mongoose_client_api/mongoose_client_api_contacts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ handle_get(Req, State = #{jid := UserJid}) ->
Bindings = cowboy_req:bindings(Req),
assert_no_jid(Bindings),
{ok, Contacts} = mod_roster_api:list_contacts(UserJid),
%CHANGED
{[jiffy:encode(lists:map(fun roster_info/1, Contacts))], Req, State}.
{jiffy:encode(lists:map(fun roster_info/1, Contacts)), Req, State}.

handle_post(Req, State = #{jid := UserJid}) ->
Args = parse_body(Req),
Expand Down Expand Up @@ -110,8 +109,7 @@ handle_delete(Req, State = #{jid := UserJid}) ->
ContactJids = get_jids_to_delete(Args),
NotDeleted = delete_contacts(UserJid, ContactJids),
RespBody = #{not_deleted => lists:map(fun jid:to_binary/1, NotDeleted)},
%CHANGED
Req2 = cowboy_req:set_resp_body([jiffy:encode(RespBody)], Req),
Req2 = cowboy_req:set_resp_body(jiffy:encode(RespBody), Req),
Req3 = cowboy_req:set_resp_header(<<"content-type">>, <<"application/json">>, Req2),
{true, Req3, State};
ContactJid ->
Expand Down
6 changes: 2 additions & 4 deletions src/mongoose_client_api/mongoose_client_api_messages.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ handle_get(Req, State = #{jid := OwnerJid}) ->
{ok, {Rows, _Limit}} =
mongoose_stanza_api:lookup_recent_messages(OwnerJid, WithJid, Before, Limit, false),
Resp = [make_json_msg(Msg, MAMId) || #{id := MAMId, packet := Msg} <- Rows],
%CHANGED
{[jiffy:encode(Resp)], Req, State}.
{jiffy:encode(Resp), Req, State}.

handle_post(Req, State = #{jid := UserJid}) ->
Args = parse_body(Req),
To = get_to(Args),
Body = get_body(Args),
{ok, Resp} = mongoose_stanza_api:send_chat_message(UserJid, undefined, To, Body),
%CHANGED
Req2 = cowboy_req:set_resp_body([jiffy:encode(Resp)], Req),
Req2 = cowboy_req:set_resp_body(jiffy:encode(Resp), Req),
{true, Req2, State}.

get_limit(#{limit := LimitBin}) ->
Expand Down
9 changes: 3 additions & 6 deletions src/mongoose_client_api/mongoose_client_api_rooms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ handle_get(Req, State = #{jid := UserJid}) ->
case get_room_jid(Bindings, State, optional) of
undefined ->
{ok, Rooms} = mod_muc_light_api:get_user_rooms(UserJid),
%CHANGED
{[jiffy:encode(lists:flatmap(fun room_us_to_json/1, Rooms))], Req, State};
{jiffy:encode(lists:flatmap(fun room_us_to_json/1, Rooms)), Req, State};
RoomJid ->
case mod_muc_light_api:get_room_info(RoomJid, UserJid) of
{ok, Info} ->
%CHANGED
{[jiffy:encode(room_info_to_json(Info))], Req, State};
{jiffy:encode(room_info_to_json(Info)), Req, State};
{room_not_found, Msg} ->
throw_error(not_found, Msg);
{not_room_member, Msg} ->
Expand Down Expand Up @@ -120,8 +118,7 @@ handle_put(Req, State = #{jid := UserJid}) ->

room_created(Req, State, RoomJid) ->
RespBody = #{<<"id">> => RoomJid#jid.luser},
%CHANGED
Req2 = cowboy_req:set_resp_body([jiffy:encode(RespBody)], Req),
Req2 = cowboy_req:set_resp_body(jiffy:encode(RespBody), Req),
Req3 = cowboy_req:reply(201, Req2),
{stop, Req3, State}.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ handle_get(Req, State = #{jid := UserJid}) ->
case mod_muc_light_api:get_room_messages(RoomJid, UserJid, Limit, Before) of
{ok, Msgs} ->
JSONData = [make_json_item(Msg) || Msg <- Msgs],
%CHANGED
{[jiffy:encode(JSONData)], Req, State};
{jiffy:encode(JSONData), Req, State};
{room_not_found, Msg} ->
throw_error(not_found, Msg);
{not_room_member, Msg} ->
Expand All @@ -93,8 +92,7 @@ handle_post(Req, State = #{jid := UserJid}) ->
case mod_muc_light_api:send_message(RoomJid, UserJid, Children, Attrs) of
{ok, _} ->
Resp = #{id => UUID},
%CHANGED
Req3 = cowboy_req:set_resp_body([jiffy:encode(Resp)], Req),
Req3 = cowboy_req:set_resp_body(jiffy:encode(Resp), Req),
{true, Req3, State};
{room_not_found, Msg} ->
throw_error(not_found, Msg);
Expand Down
7 changes: 3 additions & 4 deletions src/muc/mod_muc_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ remove_domain(HostType, MucHost, Domain) ->
store_room(HostType, MucHost, RoomName, Opts) ->
Affs = proplists:get_value(affiliations, Opts),
NewOpts = proplists:delete(affiliations, Opts),
%CHANGED
ExtOpts = [jiffy:encode({NewOpts})],
ExtOpts = jiffy:encode({NewOpts}),
F = fun() ->
forget_room_transaction(HostType, MucHost, RoomName),
store_room_transaction(HostType, MucHost, RoomName, ExtOpts, Affs)
Expand Down Expand Up @@ -220,7 +219,7 @@ store_nick_transaction(HostType, MucHost, Jid, Nick, true) ->
Error -> Error
end.

-spec store_room_transaction(mongooseim:host_type(), muc_host(), jid:luser(), binary(), term()) -> ok.
-spec store_room_transaction(mongooseim:host_type(), muc_host(), jid:luser(), iodata(), term()) -> ok.
store_room_transaction(HostType, MucHost, RoomName, ExtOpts, Affs) ->
execute_insert_room(HostType, MucHost, RoomName, ExtOpts),
Result = execute_select_room_id(HostType, MucHost, RoomName),
Expand Down Expand Up @@ -250,7 +249,7 @@ forget_room_transaction(HostType, MucHost, RoomName) ->

%% Execute call functions

-spec execute_insert_room(mongooseim:host_type(), muc_host(), jid:luser(), binary()) -> ok.
-spec execute_insert_room(mongooseim:host_type(), muc_host(), jid:luser(), iodata()) -> ok.
execute_insert_room(HostType, MucHost, RoomName, ExtOpts) ->
Args = [MucHost, RoomName, ExtOpts],
execute_successfully(HostType, muc_insert_room, Args),
Expand Down
15 changes: 5 additions & 10 deletions src/pubsub/mod_pubsub_db_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,8 @@ del_node(Nidx) ->
set_node(#pubsub_node{nodeid = {Key, Name}, id = undefined, type = Type,
owners = Owners, options = Opts, parents = Parents}) ->
ExtKey = encode_key(Key),
%CHANGED
ExtOwners = [jiffy:encode([jid:to_binary(Owner) || Owner <- Owners])],
%CHANGED
ExtOpts = [jiffy:encode({Opts})],
ExtOwners = jiffy:encode([jid:to_binary(Owner) || Owner <- Owners]),
ExtOpts = jiffy:encode({Opts}),
{updated, 1} = execute_insert_pubsub_node(ExtKey, Name, Type, ExtOwners, ExtOpts),
{selected, [Row]} = execute_select_node_by_key_and_name(ExtKey, Name),
#pubsub_node{id = Nidx} = decode_pubsub_node_row(Row),
Expand All @@ -724,8 +722,7 @@ set_node(#pubsub_node{nodeid = {Key, Name}, id = undefined, type = Type,
set_node(#pubsub_node{nodeid = {_, Name}, id = Nidx, type = Type,
owners = Owners, options = Opts, parents = Parents}) ->
OwnersJid = [jid:to_binary(Owner) || Owner <- Owners],
%CHANGED
execute_update_pubsub_node(Type, [jiffy:encode(OwnersJid)], [jiffy:encode({Opts})], Nidx),
execute_update_pubsub_node(Type, jiffy:encode(OwnersJid), jiffy:encode({Opts}), Nidx),
execute_del_parents(Name),
set_parents(Name, Parents),
{ok, Nidx}.
Expand Down Expand Up @@ -918,8 +915,7 @@ get_affiliation(Nidx, { LU, LS, _ }) ->
SubId :: mod_pubsub:subId(),
SubOpts :: mod_pubsub:subOptions()) -> ok.
add_subscription(Nidx, { LU, LS, LR }, Sub, SubId, SubOpts) ->
%CHANGED
EncodedOpts = [jiffy:encode({SubOpts})],
EncodedOpts = jiffy:encode({SubOpts}),
{updated, _} = execute_insert_subscription(Nidx, LU, LS, LR, sub2int(Sub), SubId, EncodedOpts),
ok.

Expand All @@ -928,8 +924,7 @@ add_subscription(Nidx, { LU, LS, LR }, Sub, SubId, SubOpts) ->
SubId :: mod_pubsub:subId(),
Opts :: mod_pubsub:subOptions()) -> ok.
set_subscription_opts(Nidx, { LU, LS, LR }, SubId, Opts) ->
%CHANGED
EncodedOpts = [jiffy:encode({Opts})],
EncodedOpts = jiffy:encode({Opts}),
{updated, _} = execute_update_subscription_opts(EncodedOpts, Nidx, LU, LS, LR, SubId),
ok.

Expand Down
4 changes: 2 additions & 2 deletions src/rdbms/mongoose_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
-type rdbms_msg() :: {sql_query, _}
| {sql_transaction, fun()}
| {sql_dirty, fun()}
| {sql_execute, atom(), [binary() | boolean() | integer()]}
| {sql_execute_wrapped, atom(), [binary() | boolean() | integer()], request_wrapper()}.
| {sql_execute, atom(), [iodata() | boolean() | integer()]}
| {sql_execute_wrapped, atom(), [iodata() | boolean() | integer()], request_wrapper()}.
-type single_query_result() :: {selected, [tuple()]} |
{updated, non_neg_integer() | undefined} |
{updated, non_neg_integer(), [tuple()]} |
Expand Down
3 changes: 1 addition & 2 deletions src/system_metrics/mongoose_system_metrics_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ location() ->

-spec save([mongoose_system_metrics_collector:report_struct()]) -> ok.
save(Reports) ->
%CHANGED
JSON = [jiffy:encode(Reports, [pretty])],
JSON = jiffy:encode(Reports, [pretty]),
file:write_file(location(), JSON),
ok.
3 changes: 1 addition & 2 deletions src/system_metrics/mongoose_system_metrics_sender.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ flush_reports(ReportUrl, Reports, ClientId,
#{id := TrackingId, secret := TrackingSecret}) when length(Reports) =< 25 ->
Headers = [],
ContentType = "application/json",
%CHANGED
Body = [jiffy:encode(#{client_id => list_to_binary(ClientId), events => Reports})],
Body = jiffy:encode(#{client_id => list_to_binary(ClientId), events => Reports}),
ReportUrl2 = uri_string:normalize(
ReportUrl ++ "?api_secret=" ++ TrackingSecret ++ "&measurement_id=" ++ TrackingId),
Request = {ReportUrl2, Headers, ContentType, Body},
Expand Down

0 comments on commit d603ba0

Please sign in to comment.