Просмотр исходного кода

test(emqx_dashboard): refine spec error

Zaiming (Stone) Shi 2 лет назад
Родитель
Сommit
475dee32ee

+ 10 - 4
apps/emqx_dashboard/src/emqx_dashboard_swagger.erl

@@ -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}) ->

+ 2 - 2
apps/emqx_dashboard/test/emqx_swagger_requestBody_SUITE.erl

@@ -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.

+ 2 - 5
apps/emqx_dashboard/test/emqx_swagger_response_SUITE.erl

@@ -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.