test(emqx_dashboard): refine spec error

This commit is contained in:
Zaiming (Stone) Shi 2023-04-30 17:28:41 +02:00
parent 57cc854a4a
commit 475dee32ee
3 changed files with 14 additions and 11 deletions

View File

@ -235,11 +235,17 @@ parse_spec_ref(Module, Path, Options) ->
Schema =
try
erlang:apply(Module, schema, [Path])
%% better error message
catch
error:Reason:Stacktrace ->
MoreInfo = #{module => Module, path => Path, reason => Reason},
erlang:raise(error, MoreInfo, Stacktrace)
Error:Reason:Stacktrace ->
%% This error is intended to fail the build
%% hence print to standard_error
io:format(
standard_error,
"Failed to generate swagger for path ~p in module ~p~n"
"error:~p~nreason:~p~n~p~n",
[Module, Path, Error, Reason, Stacktrace]
),
error({failed_to_generate_swagger_spec, Module, Path})
end,
{Specs, Refs} = maps:fold(
fun(Method, Meta, {Acc, RefsAcc}) ->

View File

@ -308,8 +308,8 @@ t_nest_ref(_Config) ->
t_none_ref(_Config) ->
Path = "/ref/none",
?assertThrow(
{error, #{mfa := {?MODULE, schema, [Path]}}},
?assertError(
{failed_to_generate_swagger_spec, ?MODULE, Path},
emqx_dashboard_swagger:parse_spec_ref(?MODULE, Path, #{})
),
ok.

View File

@ -278,11 +278,8 @@ t_bad_ref(_Config) ->
t_none_ref(_Config) ->
Path = "/ref/none",
?assertThrow(
{error, #{
mfa := {?MODULE, schema, ["/ref/none"]},
reason := function_clause
}},
?assertError(
{failed_to_generate_swagger_spec, ?MODULE, Path},
validate(Path, #{}, [])
),
ok.