Skip to content

Commit

Permalink
Merge pull request #295 from thalesmg/better-error-msg1
Browse files Browse the repository at this point in the history
chore: add more info to errors
  • Loading branch information
thalesmg authored Jun 6, 2024
2 parents 5f4d554 + 8a703f4 commit 76171b8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/hocon_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,23 @@ fields(Sc, Name) ->
-spec fields_and_meta(schema(), name()) -> fields().
fields_and_meta(Mod, Name) when is_atom(Mod) ->
Meta =
case Mod:fields(Name) of
try Mod:fields(Name) of
Fields when is_list(Fields) ->
maybe_add_desc(Mod, Name, #{fields => Fields});
Fields ->
ensure_struct_meta(Fields)
catch
K:E:S ->
erlang:raise(
K,
#{
error => "failed to resolve schema",
cause => E,
schema_module => Mod,
struct_name => Name
},
S
)
end,
Meta#{tags => tags(Mod)};
fields_and_meta(#{fields := Fields}, Name) when is_function(Fields) ->
Expand All @@ -290,11 +302,23 @@ fields_and_meta(#{fields := Fields}, Name) when is_map(Fields) ->
maybe_add_desc(Mod, Name, Meta) ->
case erlang:function_exported(Mod, desc, 1) of
true ->
case Mod:desc(Name) of
try Mod:desc(Name) of
undefined ->
Meta;
Desc ->
Meta#{desc => Desc}
catch
K:E:S ->
erlang:raise(
K,
#{
error => "failed to resolve struct description",
cause => E,
schema_module => Mod,
struct_name => Name
},
S
)
end;
false ->
Meta
Expand Down

0 comments on commit 76171b8

Please sign in to comment.