Skip to content

Config validation extraction#615

Open
Thomas-Mikhael wants to merge 8 commits into
eclipse-score:mainfrom
etas-contrib:feature/config_validation_extraction
Open

Config validation extraction#615
Thomas-Mikhael wants to merge 8 commits into
eclipse-score:mainfrom
etas-contrib:feature/config_validation_extraction

Conversation

@Thomas-Mikhael

@Thomas-Mikhael Thomas-Mikhael commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
  • Extract the common config validation checks into a common file/lib config_validate (preparing for use in both parsing strategies, JSON & Flatbuffer).
  • Unify the checking of duplicates while emplacing, EmplaceOrFatal()
  • Remove redundant checks of duplicate Events and Fields (CheckContainsEvent, CheckContainsField)
  • Cover a bug in the code where it allowed empty lists of events, fields and methods to pass without failing

@castler castler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

ServiceElementInstanceDeploymentParser deployment_parser{field_object};

const auto& field_name_it = field_object.find(kFieldNameKey);
deployment_parser.CheckContainsField(field_name_it, service);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not fully understand why we remove this check

@Thomas-Mikhael Thomas-Mikhael Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also do not understand fully, why we remove this check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Comment on lines +433 to +434
// That the application will terminate
SCORE_LANGUAGE_FUTURECPP_EXPECT_CONTRACT_VIOLATED(score::mw::com::impl::configuration::Parse(std::move(j2)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we consider it as a feature then we shall remove the check at all. What do you suggest?

@Thomas-Mikhael Thomas-Mikhael requested a review from castler July 3, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants