Config validation extraction#615
Conversation
castler
left a comment
There was a problem hiding this comment.
Thank you for the contribution!
I think there are two main points that contradict our current style:
1st)
We try to keep functions as local as possible - as the config checks are just used in the config parser, we should have them there as anonymous functions.
2nd)
We strictly want to allow empty services.
On a side-note it would be nice trying to avoid merge commits in Pull-Requests.
Thank you!
| { | ||
|
|
||
| template <typename Map, typename Key, typename Value> | ||
| void EmplaceOrFatal(Map& map, Key&& key, Value&& value, std::string_view element_description) |
There was a problem hiding this comment.
This function is local to config_parser.cpp thus, it should be within an anonymous namespace within the config parser.
This statement is also true for all other extractions that are done in later commits.
There was a problem hiding this comment.
This function will mostly be also used for the flatbuffer parser, that's why I put it in the common config_validate.h
If you suggest adding these files directly to the 'configuration_json_parsing_strategy' lib directly instead of making it as a separate common lib 'config_validate' that to be used later with 'configuration_flatbuffer_parsing_strategy' I would see it okay.
Or did I missunderstood something?
There was a problem hiding this comment.
No you can keep it then in a separate library. Maybe a explanation comment would be good, that explains why this is in a custom file and what the purpose if it would be.
There was a problem hiding this comment.
I have that already in the description of the PR:
Extract the common config validation checks into a common file/lib config_validate (preparing for use in both parsing strategies, JSON & Flatbuffer).
Or you mean to comment it in the Bazel BUILD file?
There was a problem hiding this comment.
I added some comments
| ServiceElementInstanceDeploymentParser deployment_parser{field_object}; | ||
|
|
||
| const auto& field_name_it = field_object.find(kFieldNameKey); | ||
| deployment_parser.CheckContainsField(field_name_it, service); |
There was a problem hiding this comment.
I do not fully understand why we remove this check
There was a problem hiding this comment.
Because it's redundant check.
CheckContainsField() and CheckContainsEvent() are using misleading naming, it is just ensuring that there's no duplicates, which would never happen using .emplace()
| ServiceElementInstanceDeploymentParser deployment_parser{event_object}; | ||
|
|
||
| const auto& event_name_it = event_object.find(kEventNameKey.data()); | ||
| deployment_parser.CheckContainsEvent(event_name_it, service); |
There was a problem hiding this comment.
I also do not understand fully, why we remove this check?
There was a problem hiding this comment.
Because it's redundant check.
CheckContainsField() and CheckContainsEvent() are using misleading naming, it is just ensuring that there's no duplicates, which would never happen using .emplace()
| // That the application will terminate | ||
| SCORE_LANGUAGE_FUTURECPP_EXPECT_CONTRACT_VIOLATED(score::mw::com::impl::configuration::Parse(std::move(j2))); |
There was a problem hiding this comment.
Its not a bug - its a feature :)
There have been use cases in the past, where an empty service was used. We see no reason why an empty service (e.g. as marker via the service discovery) shall not be allowed.
Can you maybe elaborate a bit, why you think this is a bug?
There was a problem hiding this comment.
In the original code you can see the in config_parser.cpp the error message description as following:
score::mw::log::LogFatal("lola") << "Configuration should contain at least one event, field, or method.";
That's why I considered it as an unintended bug.
There was a problem hiding this comment.
If we consider it as a feature then we shall remove the check at all. What do you suggest?
There was a problem hiding this comment.
If we consider it as a feature then we shall remove the check at all. What do you suggest?
That would be great! Then things should be more consistent!
There was a problem hiding this comment.
Removed and reverted the Tests changes
castler
left a comment
There was a problem hiding this comment.
Thanks the changes look good.
The only thing I would ask you to clean up the git history, right now its quite some mess. I am fine with having few proper commits (with proper messages).
In addition - but this could be done in a follow up if you want - we have the best practice that for each library we have our custom tests.
Since you now extracted these functions into config_validate they are most certainly covered via the existing test. But we would now normally rather create a custom config_validate_test.cpp to ensure that only this unit is correctly covered.
+ Remove redundant checks of duplicate Events and Fields (CheckContainsEvent, CheckContainsField) + Change ParseLolaxxx functions to return void instead of ignoring the return
634fdd3 to
c5ba3e2
Compare
f88e3d7 to
58c4671
Compare
|
@castler I agree. |
Uh oh!
There was an error while loading. Please reload this page.