Skip to content

Commit

Permalink
Always match against missing required variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zinid committed Jul 16, 2019
1 parent 31413d7 commit 08a1efb
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/flex_offline.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -215,6 +217,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_number_of_messages(non_neg_integer() |
Expand Down
5 changes: 5 additions & 0 deletions src/http_upload.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/2, encode/3, encode/4]).
Expand Down Expand Up @@ -217,6 +219,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec 'encode_max-file-size'(non_neg_integer() |
Expand Down
5 changes: 5 additions & 0 deletions src/mam_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -294,6 +296,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_with(jid:jid() | undefined, binary(),
Expand Down
2 changes: 2 additions & 0 deletions src/muc_register.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down
2 changes: 2 additions & 0 deletions src/muc_request.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down
5 changes: 5 additions & 0 deletions src/muc_roomconfig.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -1381,6 +1383,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_maxhistoryfetch(binary(), binary(),
Expand Down
5 changes: 5 additions & 0 deletions src/muc_roominfo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -674,6 +676,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_maxhistoryfetch(non_neg_integer() |
Expand Down
2 changes: 2 additions & 0 deletions src/pubsub_get_pending.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down
5 changes: 5 additions & 0 deletions src/pubsub_meta_data.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -525,6 +527,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_contact([jid:jid()], binary(),
Expand Down
5 changes: 5 additions & 0 deletions src/pubsub_node_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -1290,6 +1292,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_access_model(access_model() | undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/pubsub_publish_options.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -258,6 +260,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_persist_items(boolean() | undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/pubsub_subscribe_authorization.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down
5 changes: 5 additions & 0 deletions src/pubsub_subscribe_options.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -453,6 +455,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec encode_deliver(boolean() | undefined, binary(),
Expand Down
5 changes: 5 additions & 0 deletions src/push_summary.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
{dec_bool, 1}, {enc_bool, 1}, {dec_ip, 1},
{enc_ip, 1}]}).

-compile(nowarn_unused_vars).

-dialyzer({nowarn_function, {dec_int, 3}}).

-export([encode/1, encode/2, encode/3]).
Expand Down Expand Up @@ -318,6 +320,9 @@ do_decode([#xdata_field{var = Var} | Fs], XMLNS,
erlang:error({?MODULE, {unknown_var, Var, XMLNS}});
true -> do_decode(Fs, XMLNS, Required, Acc)
end;
do_decode([], XMLNS, [Var | _], _) ->
erlang:error({?MODULE,
{missing_required_var, Var, XMLNS}});
do_decode([], _, [], Acc) -> Acc.

-spec 'encode_message-count'(non_neg_integer() |
Expand Down
9 changes: 3 additions & 6 deletions src/xdata_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ mk_header(#state{mod_name = Mod, hrl = Include, xmlns = NS} = State) ->
mk_comment_header(State),
emit("~n-module(~s).~n", [Mod]),
emit("-compile({nowarn_unused_function, ~p}).~n", [codec_funs()]),
emit("-compile(nowarn_unused_vars).~n"),
emit("-dialyzer({nowarn_function, dec_int/3}).~n"),
case NS of
[_] -> emit("-export([encode/1, encode/2, encode/3]).~n");
Expand Down Expand Up @@ -498,12 +499,8 @@ mk_decoder([], State) ->
" do_decode(Fs, XMLNS, Required, Acc)"
" end;")
end,
if State#state.required /= [] ->
emit("do_decode([], XMLNS, [Var|_], _) ->"
" erlang:error({?MODULE, {missing_required_var, Var, XMLNS}});~n");
true ->
ok
end,
emit("do_decode([], XMLNS, [Var|_], _) ->"
" erlang:error({?MODULE, {missing_required_var, Var, XMLNS}});~n"),
emit("do_decode([], _, [], Acc) -> Acc.~n").

mk_encoders(Fs, State) ->
Expand Down

0 comments on commit 08a1efb

Please sign in to comment.