From 61d6733d7b1725c79bbaedc4cbd3fd5b107a6956 Mon Sep 17 00:00:00 2001 From: Dairon Medina Caro Date: Sat, 8 Feb 2020 00:30:29 -0500 Subject: [PATCH 1/2] Show clique status message instead of throwing an error and stacktrace when an Arg value is empty --- src/clique_error.erl | 2 ++ src/clique_parser.erl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clique_error.erl b/src/clique_error.erl index f1397fb..a788276 100644 --- a/src/clique_error.erl +++ b/src/clique_error.erl @@ -58,6 +58,8 @@ format(_Cmd, {error, {invalid_flags, Flags}}) -> status(io_lib:format("Invalid Flags: ~p", [Flags])); format(_Cmd, {error, {invalid_flag_value, {Name, Val}}}) -> status(io_lib:format("Invalid value: ~p for flag: ~p", [Val, Name])); +format(_Cmd, {error, {invalid_kv_arg, Arg}}) -> + status(io_lib:format("Empty value in argument: ~p", [Arg])); format(_Cmd, {error, {invalid_flag_combination, Msg}}) -> status(io_lib:format("Error: ~ts", [Msg])); format(_Cmd, {error, {invalid_value, Val}}) -> diff --git a/src/clique_parser.erl b/src/clique_parser.erl index a12c6a6..e98e359 100644 --- a/src/clique_parser.erl +++ b/src/clique_parser.erl @@ -380,7 +380,7 @@ parse_valid_arg_value_with_equal_sign_test() -> %% All arguments must be of type k=v parse_invalid_kv_arg_test() -> Spec = spec(), - Args = ["ayo"], + Args = ["ayo="], ?assertMatch({error, _}, parse({Spec, Args})). %% This succeeds, because we aren't validating the flag, just parsing From 06247fd6ead6637a3c0088bfb73c147a74ccd78a Mon Sep 17 00:00:00 2001 From: Dairon Medina Caro Date: Sat, 8 Feb 2020 22:15:44 -0500 Subject: [PATCH 2/2] Add test improvements to check for both no equal sign and no value --- src/clique_parser.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/clique_parser.erl b/src/clique_parser.erl index e98e359..d606229 100644 --- a/src/clique_parser.erl +++ b/src/clique_parser.erl @@ -380,8 +380,13 @@ parse_valid_arg_value_with_equal_sign_test() -> %% All arguments must be of type k=v parse_invalid_kv_arg_test() -> Spec = spec(), - Args = ["ayo="], - ?assertMatch({error, _}, parse({Spec, Args})). + %% Argument with equal sign and no value + ArgsNoVal = ["ayo="], + ?assertMatch({error, {invalid_kv_arg, _}}, parse({Spec, ArgsNoVal})), + %% Argument without equal sign and no value + ArgsNoEqualAndNoVal = ["ayo"], + ?assertMatch({error, {invalid_kv_arg, _}}, parse({Spec, ArgsNoEqualAndNoVal})). + %% This succeeds, because we aren't validating the flag, just parsing %% Note: Short flags get parsed into tuples with their character as first elem