Skip to content

Conversation

@vrygl
Copy link

@vrygl vrygl commented Dec 5, 2025

When there is module in config file defined under external-connection::endpoints that is not defined in global module-paths config, it crashed the module-gateway when it attempted to connect to external server.

This pull request fixes the crash and prevents start of gateway with incorrect configuration file.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced robustness of external device connection lookups with safer error handling that gracefully manages missing modules
    • Added configuration validation to ensure all modules referenced in connection endpoints are properly defined
  • Tests

    • Added test case to verify proper error detection when configuration contains undefined module references

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce safer module lookup patterns and add cross-reference validation to ensure modules referenced in external connection endpoints exist in module configurations. Three files are modified: one implements defensive map access, one adds validation logic, and one introduces test coverage.

Changes

Cohort / File(s) Summary
Safe module lookup
source/bringauto/external_client/connection/ExternalConnection.cpp
Replaced direct map access .at(moduleNumber) with .find(moduleNumber) for statusAggregators. Logs warning and continues if module not found; otherwise uses iterator to access status aggregator.
Cross-reference validation
source/bringauto/settings/SettingsParser.cpp
Added validation in areSettingsCorrect() to ensure every module referenced in external connection endpoint modules exists in modulePaths. Logs error and sets validation to false if modules are missing.
Test coverage
test/source/SettingsParserTests.cpp
Added new test case MissingModules to verify that parseConfig() throws std::invalid_argument when endpoint modules reference a module ID not present in module_paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • ExternalConnection.cpp: Verify the .find() logic correctly handles missing modules and that the warning log is appropriate.
  • SettingsParser.cpp: Ensure the nested search logic correctly identifies missing module cross-references and that validation integrates properly with existing checks.
  • SettingsParserTests.cpp: Confirm test expectations align with the new validation behavior and exception handling.

Possibly related PRs

  • module-gateway#31: Modifies ExternalConnection.cpp and touches status-aggregation logic; overlaps with safe lookup patterns and aggregator handling in this PR.

Suggested reviewers

  • koudis

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main fix: preventing gateway crashes when endpoints reference missing modules.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vrygl
Copy link
Author

vrygl commented Dec 5, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
source/bringauto/settings/SettingsParser.cpp (1)

112-122: Validation logic is correct, but relies on C++20 and only reports the first missing module

The new cross-check correctly makes settings invalid if any endpoint module is not present in modulePaths, and it logs an error on detection. Two points to consider:

  1. Toolchain requirements

    • std::ranges::any_of and settings_->modulePaths.contains(externalModuleId) are C++20 features. Ensure your build uses C++20; if you must stay on C++17, you’ll need to replace them (e.g. regular loops + count(...) == 0).
  2. Diagnostics only for the first missing module

    • Because both std::ranges::any_of calls short‑circuit, you only log for the first missing module in the first failing endpoint. If you’d like to report all missing modules across all endpoints (in line with other validations that iterate over everything), you could switch to explicit loops:
-    isCorrect &= !std::ranges::any_of(settings_->externalConnectionSettingsList, [&](auto& externalConnectionSettings){
-        return std::ranges::any_of(externalConnectionSettings.modules, [&](auto const& externalModuleId) {
-            bool isMissing = !settings_->modulePaths.contains(externalModuleId);
-            if (isMissing)
-            {
-                std::cerr << "Module " << externalModuleId <<
-                " is defined in external-connection endpoint modules but is not specified in module-paths" << std::endl;
-            }
-            return isMissing;
-        });
-    });
+    bool hasMissingModules = false;
+    for (const auto& externalConnectionSettings : settings_->externalConnectionSettingsList) {
+        for (const auto externalModuleId : externalConnectionSettings.modules) {
+            const bool isMissing = !settings_->modulePaths.contains(externalModuleId);
+            if (isMissing) {
+                std::cerr << "Module " << externalModuleId
+                          << " is defined in external-connection endpoint modules but is not specified in module-paths"
+                          << std::endl;
+                hasMissingModules = true;
+            }
+        }
+    }
+    isCorrect &= !hasMissingModules;

This keeps the same semantics but improves diagnostics and avoids nested any_of complexity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0be5cfd and e02cf04.

📒 Files selected for processing (3)
  • source/bringauto/external_client/connection/ExternalConnection.cpp (1 hunks)
  • source/bringauto/settings/SettingsParser.cpp (2 hunks)
  • test/source/SettingsParserTests.cpp (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2024-10-03T11:24:43.894Z
Learnt from: Mayt34
Repo: bringauto/transparent-module PR: 1
File: source/bringauto/modules/devices/testing_device/testing_module_manager.cpp:25-34
Timestamp: 2024-10-03T11:24:43.894Z
Learning: In the `testing_device_aggregate_status` function for the testing device, status aggregation of current and new status is not necessary due to the module's simple logic, similar to the io-module which works without aggregation.

Applied to files:

  • source/bringauto/external_client/connection/ExternalConnection.cpp
📚 Learning: 2024-10-04T07:17:14.935Z
Learnt from: Mayt34
Repo: bringauto/transparent-module PR: 1
File: source/external_server_api.cpp:231-263
Timestamp: 2024-10-04T07:17:14.935Z
Learning: In `external_server_api.cpp`, the number of devices will always be small, so it's acceptable to use a vector for device storage in functions like `device_connected` and `device_disconnected`, and optimizing with a hash table is unnecessary.

Applied to files:

  • source/bringauto/external_client/connection/ExternalConnection.cpp
📚 Learning: 2024-11-06T13:26:30.538Z
Learnt from: MarioIvancik
Repo: bringauto/virtual-vehicle PR: 19
File: test/source/SettingsParserTest.cpp:264-264
Timestamp: 2024-11-06T13:26:30.538Z
Learning: In `test/source/SettingsParserTest.cpp`, the exception messages expected in the unit tests are correct and consistent, matching the actual messages thrown by `parseConfig`, and the unit tests are passing.

Applied to files:

  • test/source/SettingsParserTests.cpp
  • source/bringauto/settings/SettingsParser.cpp
📚 Learning: 2024-11-06T13:25:36.211Z
Learnt from: MarioIvancik
Repo: bringauto/virtual-vehicle PR: 19
File: test/source/SettingsParserTest.cpp:259-268
Timestamp: 2024-11-06T13:25:36.211Z
Learning: In `SettingsParserTest.cpp`, the `parseConfig` function adds the `--config` parameter by default, so providing another `--config` parameter results in duplicate command-line options for testing purposes.

Applied to files:

  • test/source/SettingsParserTests.cpp
📚 Learning: 2024-10-31T10:45:48.494Z
Learnt from: MarioIvancik
Repo: bringauto/module-gateway PR: 38
File: include/bringauto/structures/LoggingSettings.hpp:10-15
Timestamp: 2024-10-31T10:45:48.494Z
Learning: In the ModuleGateway project, values in the structures defined in `include/bringauto/structures/LoggingSettings.hpp` are validated in `SettingsParser.cpp`, so additional validation within the structures is unnecessary.

Applied to files:

  • test/source/SettingsParserTests.cpp
  • source/bringauto/settings/SettingsParser.cpp
📚 Learning: 2024-10-31T10:43:48.276Z
Learnt from: MarioIvancik
Repo: bringauto/module-gateway PR: 38
File: include/bringauto/structures/LoggingSettings.hpp:17-24
Timestamp: 2024-10-31T10:43:48.276Z
Learning: In the C++ codebase, the `FileSettings` structure's values are validated in `SettingsParser`.

Applied to files:

  • source/bringauto/settings/SettingsParser.cpp
📚 Learning: 2024-10-31T10:44:39.657Z
Learnt from: MarioIvancik
Repo: bringauto/module-gateway PR: 38
File: include/bringauto/structures/LoggingSettings.hpp:26-31
Timestamp: 2024-10-31T10:44:39.657Z
Learning: In the `ModuleGateway` project, logging settings are validated in `SettingsParser`, so additional validation in the `LoggingSettings` structure is not necessary.

Applied to files:

  • source/bringauto/settings/SettingsParser.cpp
🧬 Code graph analysis (2)
source/bringauto/external_client/connection/ExternalConnection.cpp (1)
include/bringauto/settings/LoggerWrapper.hpp (2)
  • logWarning (51-56)
  • logWarning (51-51)
test/source/SettingsParserTests.cpp (1)
test/include/SettingsParserTests.hpp (2)
  • config (22-39)
  • config (22-22)
🔇 Additional comments (2)
source/bringauto/settings/SettingsParser.cpp (1)

8-8: Confirm C++20 availability for <ranges>

The new #include <ranges> is required for std::ranges::any_of used below. Please confirm the project is compiled with at least C++20 (or a libstdc++/libc++ that fully supports <ranges>); otherwise this will fail to build on older toolchains.

test/source/SettingsParserTests.cpp (1)

189-205: New MissingModules test correctly covers the validation path

The test setup (module_paths {1,2,3} vs endpoint.modules {1,2,3,4}) and assertion on std::invalid_argument("Arguments are not correct.") align with the new settings validation and existing test patterns. Looks good.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2025

@vrygl vrygl assigned koudis and unassigned koudis Dec 17, 2025
@vrygl vrygl requested a review from koudis December 17, 2025 13:58
@vrygl vrygl self-assigned this Dec 17, 2025
@koudis koudis merged commit 8823278 into BAF-1155/use_async_client Jan 13, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants