-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add more info to errors #295
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zmstone
reviewed
Jun 5, 2024
src/hocon_schema.erl
Outdated
Fields when is_list(Fields) -> | ||
maybe_add_desc(Mod, Name, #{fields => Fields}); | ||
Fields -> | ||
ensure_struct_meta(Fields) | ||
catch | ||
error:function_clause -> | ||
throw({missing_struct_def, Mod, Name}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catch all kinds of errors
erlang:raise with error reason enriched and with original stackstace.
function_clause may happen in deeper stack under Mod:fields
Before the change: ``` [error] input-config: '$hcVal' => [#{'$hcTyp' => object, '$hcVal' => #{<<"key">> => #{'$hcTyp' => string,'$hcVal' => <<"ts">>, '$hcMeta' => #{line => 45, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, <<"value">> => #{'$hcTyp' => string, '$hcVal' => <<"concat([topic, '/', a.b])">>, '$hcMeta' => #{line => 46, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}}, '$hcMeta' => #{line => 46, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}], '$hcMeta' => #{line => 43, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}} path => "message_transformation.transformations.1", exception => function_clause,field => <<"transform">>} <---------------------------------------- escript: exception error: #{reason => failed_to_check_field, path => "message_transformation.transformations.1", exception => function_clause,field => <<"transform">>} in function emqx_message_transformation_schema:fields/1 called as emqx_message_transformation_schema:fields(transform_kv222) in call from hocon_schema:fields_and_meta/2 (hocon_schema.erl, line 278) in call from hocon_schema:fields/2 (hocon_schema.erl, line 271) in call from hocon_tconf:map_field/4 (hocon_tconf.erl, line 584) in call from hocon_tconf:map_one_field_non_hidden/4 (hocon_tconf.erl, line 492) in call from hocon_tconf:do_map_array/5 (hocon_tconf.erl, line 801) in call from hocon_tconf:'-map_field/4-fun-4-'/4 (hocon_tconf.erl, line 622) in call from hocon_tconf:map_one_field_non_hidden/4 (hocon_tconf.erl, line 492) ``` After the change: ``` [error] input-config: '$hcVal' => [#{'$hcTyp' => object, '$hcVal' => #{<<"key">> => #{'$hcTyp' => string,'$hcVal' => <<"ts">>, '$hcMeta' => #{line => 45, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, <<"value">> => #{'$hcTyp' => string, '$hcVal' => <<"concat([topic, '/', a.b])">>, '$hcMeta' => #{line => 46, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}}, '$hcMeta' => #{line => 46, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, #{'$hcTyp' => object, '$hcVal' => #{<<"key">> => #{'$hcTyp' => string,'$hcVal' => <<"bah">>, '$hcMeta' => #{line => 49, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, <<"value">> => #{'$hcTyp' => string, '$hcVal' => <<"schema_decode('avro', 'bah')">>, '$hcMeta' => #{line => 50, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}}, '$hcMeta' => #{line => 50, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, #{'$hcTyp' => object, '$hcVal' => #{<<"key">> => #{'$hcTyp' => string,'$hcVal' => <<"bah">>, '$hcMeta' => #{line => 53, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}, <<"value">> => #{'$hcTyp' => string, '$hcVal' => <<"schema_encode('avro', 'bah')">>, '$hcMeta' => #{line => 54, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}}, '$hcMeta' => #{line => 54, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}}], '$hcMeta' => #{line => 43, filename => "/home/thales/dev/emqx/emqx/_build/emqx-enterprise/rel/emqx/data/configs/cluster.hocon"}} path => "message_transformation.transformations.1", exception => #{reason => function_clause, <----------------------------------------------------- stacktrace => [{emqx_message_transformation_schema,fields, [operation_wrong_ref], [{file,"emqx_message_transformation_schema.erl"},{line,39}]}, {hocon_schema,fields_and_meta,2, [{file,"hocon_schema.erl"},{line,278}]}, {hocon_schema,fields,2,[{file,"hocon_schema.erl"},{line,271}]}, {hocon_tconf,map_field,4,[{file,"hocon_tconf.erl"},{line,581}]}, {hocon_tconf,map_one_field_non_hidden,4, [{file,"hocon_tconf.erl"},{line,492}]}, {hocon_tconf,do_map_array,5, [{file,"hocon_tconf.erl"},{line,798}]}, {hocon_tconf,'-map_field/4-fun-4-',4, [{file,"hocon_tconf.erl"},{line,619}]}, {hocon_tconf,map_one_field_non_hidden,4, [{file,"hocon_tconf.erl"},{line,492}]}], kind => error}, field => <<"operations">>} escript: exception throw: #{reason => failed_to_check_field, path => "message_transformation.transformations.1", exception => #{reason => function_clause, stacktrace => [{emqx_message_transformation_schema,fields, [operation_wrong_ref], [{file, "emqx_message_transformation_schema.erl"}, {line,39}]}, {hocon_schema,fields_and_meta,2, [{file,"hocon_schema.erl"},{line,278}]}, {hocon_schema,fields,2, [{file,"hocon_schema.erl"},{line,271}]}, {hocon_tconf,map_field,4, [{file,"hocon_tconf.erl"},{line,581}]}, {hocon_tconf,map_one_field_non_hidden,4, [{file,"hocon_tconf.erl"},{line,492}]}, {hocon_tconf,do_map_array,5, [{file,"hocon_tconf.erl"},{line,798}]}, {hocon_tconf,'-map_field/4-fun-4-',4, [{file,"hocon_tconf.erl"},{line,619}]}, {hocon_tconf,map_one_field_non_hidden,4, [{file,"hocon_tconf.erl"},{line,492}]}], kind => error}, field => <<"operations">>} ```
850c7e9
to
68432a3
Compare
zmstone
reviewed
Jun 5, 2024
zmstone
reviewed
Jun 5, 2024
Co-authored-by: zmstone <zmstone@gmail.com>
zmstone
approved these changes
Jun 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Minor change to replace
function_clause
with a bit more info to track down the error.Before the change:
After the change: