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 ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
#{
|
try
|
||||||
text => short_name(FullName),
|
#{
|
||||||
hash => format_hash(FullName),
|
text => short_name(FullName),
|
||||||
doc => maps:get(desc, S, <<"">>),
|
hash => format_hash(FullName),
|
||||||
fields => format_fields(Fields, DescResolver)
|
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_fields(Fields, DescResolver) ->
|
||||||
[format_field(F, DescResolver) || F <- Fields].
|
[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
|
%% Module is ignored so far as all types are distinguished by their names
|
||||||
readable(TypeStr)
|
readable(TypeStr)
|
||||||
catch
|
catch
|
||||||
throw:unknown_type ->
|
throw:Reason ->
|
||||||
fail(#{reason => unknown_type, type => TypeStr, module => Module})
|
throw(#{
|
||||||
|
reason => Reason,
|
||||||
|
type => TypeStr,
|
||||||
|
module => Module
|
||||||
|
});
|
||||||
|
error:Reason:Stacktrace ->
|
||||||
|
throw(#{
|
||||||
|
reason => Reason,
|
||||||
|
stacktrace => Stacktrace,
|
||||||
|
type => TypeStr,
|
||||||
|
module => Module
|
||||||
|
})
|
||||||
end.
|
end.
|
||||||
|
|
||||||
readable_swagger(Module, TypeStr) ->
|
readable_swagger(Module, TypeStr) ->
|
||||||
|
@ -49,16 +60,10 @@ readable_docgen(Module, TypeStr) ->
|
||||||
get_readable(Module, TypeStr, Flavor) ->
|
get_readable(Module, TypeStr, Flavor) ->
|
||||||
Map = readable(Module, TypeStr),
|
Map = readable(Module, TypeStr),
|
||||||
case maps:get(Flavor, Map, undefined) of
|
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
|
Value -> Value
|
||||||
end.
|
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()") ->
|
readable("boolean()") ->
|
||||||
#{
|
#{
|
||||||
swagger => #{type => boolean},
|
swagger => #{type => boolean},
|
||||||
|
|
Loading…
Reference in New Issue