test(emqx_dashboard): refine spec error
This commit is contained in:
parent
57cc854a4a
commit
475dee32ee
|
@ -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}) ->
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue