Skip to content

Feat: Implement better location reporting (Issue #158)#161

Open
miker2 wants to merge 5 commits intomainfrom
feat/issue-158
Open

Feat: Implement better location reporting (Issue #158)#161
miker2 wants to merge 5 commits intomainfrom
feat/issue-158

Conversation

@miker2
Copy link
Owner

@miker2 miker2 commented Jun 26, 2025

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @miker2, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the debugging and traceability of configuration values within the system. It introduces a comprehensive mechanism to track the full lineage of a configuration item, providing a detailed history of how it was derived through various processing steps like references, variable substitutions, and expression evaluations. This enhancement provides much richer context for understanding the provenance of any given configuration value.

Highlights

  • Enhanced Location Tracking: I've introduced an origins vector to the ConfigBase class to track the lineage of configuration values. This allows the loc() method to report not just the immediate source file and line, but also a chain of where the value originated from (e.g., through references, variable substitutions, or expressions).
  • Propagation of Origin Information: I've modified several key helper functions in src/config_helpers.cpp (structFromReference, replaceProtoVar, resolveVarRefs, evaluateExpression) to correctly populate and propagate the new origins vector. This ensures that as configuration values are created, cloned, or transformed, their full derivation history is preserved.
  • New Test Case for Location Reporting: I've added a new LocationReporting test case to tests/config_parse_test.cpp. This test specifically verifies that the enhanced loc() functionality correctly outputs the detailed origin chain, confirming the feature works as intended.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces an important feature for better location reporting, which will be very helpful for debugging configurations. I've identified a few critical issues related to state modification of shared objects and test portability that need to be addressed. There's also a high-severity issue with how origins are added to expressions, which could lead to confusing location reports.

}
// Get the new value based on the kValueLookup object.
value = getConfigValue(root, kv_lookup);
value->origins.push_back(kv_lookup); // Add the lookup to the origins

Choose a reason for hiding this comment

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

critical

Modifying the origins of a value object retrieved from the configuration map via getConfigValue can lead to incorrect origin information for other references, representing a state corruption bug.

Comment on lines 328 to 329
EXPECT_THAT(output, testing::HasSubstr("var_ref1 = \"test\" # /Users/michael/repos/flexi_config_reader/examples/env/env_example1.cfg:1 (from /Users/michael/repos/flexi_config_reader/examples/config_example13.cfg:5)"));
EXPECT_THAT(output, testing::HasSubstr("var_ref2 = \"test\" # /Users/michael/repos/flexi_config_reader/examples/env/env_example2.cfg:2 (from /Users/michael/repos/flexi_config_reader/examples/config_example13.cfg:6)"));

Choose a reason for hiding this comment

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

critical

The test LocationReporting uses hardcoded absolute paths in EXPECT_THAT. This will cause the test to fail on any other machine or in a CI environment where the project path is different. Please use the baseDir() helper to construct the expected paths dynamically.

Suggested change
EXPECT_THAT(output, testing::HasSubstr("var_ref1 = \"test\" # /Users/michael/repos/flexi_config_reader/examples/env/env_example1.cfg:1 (from /Users/michael/repos/flexi_config_reader/examples/config_example13.cfg:5)"));
EXPECT_THAT(output, testing::HasSubstr("var_ref2 = \"test\" # /Users/michael/repos/flexi_config_reader/examples/env/env_example2.cfg:2 (from /Users/michael/repos/flexi_config_reader/examples/config_example13.cfg:6)"));
const auto base_path = baseDir();
const auto expected_loc1 = (base_path / "env/env_example1.cfg").string();
const auto config_path = (base_path / "config_example13.cfg").string();
const auto expected_loc3 = (base_path / "env/env_example2.cfg").string();
EXPECT_THAT(output, testing::HasSubstr(fmt::format("var_ref1 = \"test\" # {}:1 (from {}:5)", expected_loc1, config_path)));
EXPECT_THAT(output, testing::HasSubstr(fmt::format("var_ref2 = \"test\" # {}:2 (from {}:6)", expected_loc3, config_path)));

Comment on lines 294 to 297
// Add the resolved variables to the origins of the new expression
for (const auto& rkv : ref_vars) {
state.obj_res->origins.push_back(rkv.second);
}

Choose a reason for hiding this comment

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

high

This loop adds all variables from ref_vars to the new expression's origins. However, the expression may only use a subset of these variables, leading to inaccurate location information.

Comment on lines 69 to 77
if (!origins.empty()) {
s += " (from ";
for (size_t i = 0; i < origins.size(); ++i) {
s += fmt::format("{}:{}", origins[i]->source, origins[i]->line);
if (i < origins.size() - 1) {
s += " <-";
}
}
s += ")";

Choose a reason for hiding this comment

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

medium

This loop for constructing the origin string can be made more concise and potentially more efficient by using fmt::join with a range view. This avoids manual handling of separators and string concatenation in a loop.

    s += " (from ";
    auto origin_locs = origins | ranges::views::transform([](const auto& o) {
      return fmt::format("{}:{}", o->source, o->line);
    });
    s += fmt::join(origin_locs, " <- ");
    s += ")";

miker2 and others added 4 commits June 26, 2025 00:02
- The value from getConfigValue is already cloned, so no state corruption
- Fixed hardcoded absolute paths in LocationReporting test
- Only add variables to origins that were actually used in expressions
- Optimized origin string construction using fmt::join
- Fixed proto variable resolution showing :0 by ensuring ConfigReference gets proper location info
- Fixed variable substitution preserving source/line information through resolve chain
- Fixed list location reporting when elements lose location info during resolution
- Added comprehensive test coverage for all reference types:
  * Proto variable substitution location reporting
  * Value lookup reference location reporting
  * Expression evaluation location reporting
  * Variable substitution in complex scenarios

All reference types now properly report:
1. Original definition location
2. Reference chain with "from" annotations
3. Proper file paths and line numbers

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed incorrect link text from 'example_config1.cfg' to 'config_example1.cfg'
- Updated grammar and actions file paths from 'cpp/' to 'include/flexi_cfg/config/'
- Fixed config_build usage example: 'config_reader' → 'config_build', 'example/' → 'examples/'

All referenced files now exist and links are accurate.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant