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 =
|
Schema =
|
||||||
try
|
try
|
||||||
erlang:apply(Module, schema, [Path])
|
erlang:apply(Module, schema, [Path])
|
||||||
%% better error message
|
|
||||||
catch
|
catch
|
||||||
error:Reason:Stacktrace ->
|
Error:Reason:Stacktrace ->
|
||||||
MoreInfo = #{module => Module, path => Path, reason => Reason},
|
%% This error is intended to fail the build
|
||||||
erlang:raise(error, MoreInfo, Stacktrace)
|
%% 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,
|
end,
|
||||||
{Specs, Refs} = maps:fold(
|
{Specs, Refs} = maps:fold(
|
||||||
fun(Method, Meta, {Acc, RefsAcc}) ->
|
fun(Method, Meta, {Acc, RefsAcc}) ->
|
||||||
|
|
|
@ -308,8 +308,8 @@ t_nest_ref(_Config) ->
|
||||||
|
|
||||||
t_none_ref(_Config) ->
|
t_none_ref(_Config) ->
|
||||||
Path = "/ref/none",
|
Path = "/ref/none",
|
||||||
?assertThrow(
|
?assertError(
|
||||||
{error, #{mfa := {?MODULE, schema, [Path]}}},
|
{failed_to_generate_swagger_spec, ?MODULE, Path},
|
||||||
emqx_dashboard_swagger:parse_spec_ref(?MODULE, Path, #{})
|
emqx_dashboard_swagger:parse_spec_ref(?MODULE, Path, #{})
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -278,11 +278,8 @@ t_bad_ref(_Config) ->
|
||||||
|
|
||||||
t_none_ref(_Config) ->
|
t_none_ref(_Config) ->
|
||||||
Path = "/ref/none",
|
Path = "/ref/none",
|
||||||
?assertThrow(
|
?assertError(
|
||||||
{error, #{
|
{failed_to_generate_swagger_spec, ?MODULE, Path},
|
||||||
mfa := {?MODULE, schema, ["/ref/none"]},
|
|
||||||
reason := function_clause
|
|
||||||
}},
|
|
||||||
validate(Path, #{}, [])
|
validate(Path, #{}, [])
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue