refactor(emqx_conf): raise exception at higher level for more context
This commit is contained in:
parent
51c8173174
commit
f9f14f9758
|
@ -304,12 +304,22 @@ gen_flat_doc(RootNames, #{full_name := FullName, fields := Fields} = S, DescReso
|
|||
false ->
|
||||
ok
|
||||
end,
|
||||
#{
|
||||
text => short_name(FullName),
|
||||
hash => format_hash(FullName),
|
||||
doc => maps:get(desc, S, <<"">>),
|
||||
fields => format_fields(Fields, DescResolver)
|
||||
}.
|
||||
try
|
||||
#{
|
||||
text => short_name(FullName),
|
||||
hash => format_hash(FullName),
|
||||
doc => maps:get(desc, S, <<"">>),
|
||||
fields => format_fields(Fields, DescResolver)
|
||||
}
|
||||
catch
|
||||
throw:Reason ->
|
||||
io:format(
|
||||
standard_error,
|
||||
"failed_to_build_doc for ~s:~n~p~n",
|
||||
[FullName, Reason]
|
||||
),
|
||||
error(failed_to_build_doc)
|
||||
end.
|
||||
|
||||
format_fields(Fields, DescResolver) ->
|
||||
[format_field(F, DescResolver) || F <- Fields].
|
||||
|
|
|
@ -33,8 +33,19 @@ readable(Module, TypeStr) when is_list(TypeStr) ->
|
|||
%% Module is ignored so far as all types are distinguished by their names
|
||||
readable(TypeStr)
|
||||
catch
|
||||
throw:unknown_type ->
|
||||
fail(#{reason => unknown_type, type => TypeStr, module => Module})
|
||||
throw:Reason ->
|
||||
throw(#{
|
||||
reason => Reason,
|
||||
type => TypeStr,
|
||||
module => Module
|
||||
});
|
||||
error:Reason:Stacktrace ->
|
||||
throw(#{
|
||||
reason => Reason,
|
||||
stacktrace => Stacktrace,
|
||||
type => TypeStr,
|
||||
module => Module
|
||||
})
|
||||
end.
|
||||
|
||||
readable_swagger(Module, TypeStr) ->
|
||||
|
@ -49,16 +60,10 @@ readable_docgen(Module, TypeStr) ->
|
|||
get_readable(Module, TypeStr, Flavor) ->
|
||||
Map = readable(Module, TypeStr),
|
||||
case maps:get(Flavor, Map, undefined) of
|
||||
undefined -> fail(#{reason => unknown_type, module => Module, type => TypeStr});
|
||||
undefined -> throw(#{reason => unknown_type, module => Module, type => TypeStr});
|
||||
Value -> Value
|
||||
end.
|
||||
|
||||
%% Fail the build or test. Production code should never get here.
|
||||
-spec fail(_) -> no_return().
|
||||
fail(Reason) ->
|
||||
io:format(standard_error, "ERROR: ~p~n", [Reason]),
|
||||
error(Reason).
|
||||
|
||||
readable("boolean()") ->
|
||||
#{
|
||||
swagger => #{type => boolean},
|
||||
|
|
Loading…
Reference in New Issue