Skip to content

Config validation extraction#615

Merged
castler merged 3 commits into
eclipse-score:mainfrom
etas-contrib:feature/config_validation_extraction
Jul 14, 2026
Merged

Config validation extraction#615
castler merged 3 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)
  • Change ParseLolaxxx functions to return void instead of ignoring the return

@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?

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.

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.

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.

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?

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.

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

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?

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.

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!

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.

Removed and reverted the Tests changes

@Thomas-Mikhael
Thomas-Mikhael requested a review from castler July 3, 2026 09:12

@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.

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
@Thomas-Mikhael
Thomas-Mikhael force-pushed the feature/config_validation_extraction branch from 634fdd3 to c5ba3e2 Compare July 14, 2026 09:46
@Thomas-Mikhael
Thomas-Mikhael force-pushed the feature/config_validation_extraction branch from f88e3d7 to 58c4671 Compare July 14, 2026 09:59
@Thomas-Mikhael
Thomas-Mikhael requested a review from castler July 14, 2026 09:59
@Thomas-Mikhael

Copy link
Copy Markdown
Contributor Author

@castler I agree.
Added config_validate_test.cpp
Fixed up the commits into 2 commits

@castler
castler enabled auto-merge July 14, 2026 11:46
@castler
castler added this pull request to the merge queue Jul 14, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 14, 2026
@castler
castler added this pull request to the merge queue Jul 14, 2026
Merged via the queue into eclipse-score:main with commit 35841ed Jul 14, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in COM - Communication FT Jul 14, 2026
@Thomas-Mikhael
Thomas-Mikhael deleted the feature/config_validation_extraction branch July 14, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants