Fix lack of warning of unrecognized section names #15335

pull AkioNak wants to merge 1 commits into bitcoin:master from AkioNak:conf_include_multi changing 5 files +36 −24
  1. AkioNak commented at 6:11 AM on February 4, 2019: contributor

    In #14708, It was introduced that to warn when unrecognized section names are exist in the config file. But m_config_sections.clear() in ArgsManager::ReadConfigStream() is called every time when reading each configuration file, so it can warn about only last reading file if includeconf exists.

    This PR fix lack of warning by collecting all section names by moving m_config_sections.clear() to ArgsManager::ReadConfigFiles() . Also add a test code to confirm this situation.

  2. fanquake added the label Utils/log/libs on Feb 4, 2019
  3. DrahtBot commented at 8:21 AM on February 4, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #14866 (Improve property evaluation way in bitcoin.conf by AkioNak)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. AkioNak commented at 8:56 AM on February 4, 2019: contributor

    If #14866 will be merged before this PR, I will drop the bug-fix code (system.cpp) , but leave the test code.

  5. MarcoFalke commented at 3:59 PM on February 4, 2019: member

    utACK f7b0e60eac70fde74684ac406967c38ba8308679

  6. MarcoFalke commented at 4:01 PM on February 4, 2019: member

    test-nit: Wouldn't it be cleaner to also clear them in ReadConfigString?

  7. AkioNak commented at 7:51 AM on February 5, 2019: contributor

    @MarcoFalke Thank you for your review. I'm sorry, but I don't understand. Is ReadConfigString related to this Python test?

    I think removing includeconf=~ from including file rather than making both 2 included file empty is another idea.

  8. promag commented at 2:44 PM on February 5, 2019: member

    Concept ACK.

    I wonder if it should warn unrecognized sections per file (section + file + line)? It also avoid duplicate warns but maybe it shouldn't.

  9. MarcoFalke commented at 3:41 PM on February 5, 2019: member

    @AkioNak The unit tests don't read from files, but from strings. Since you moved the clear() to the method that reads files, it would no longer be called in the unit tests.

  10. AkioNak commented at 4:24 PM on February 5, 2019: contributor

    @promag Thank you for your review. I did not focus on that behavior. Will address.

  11. AkioNak commented at 4:28 PM on February 5, 2019: contributor

    @MarcoFalke Thanks! I understand. I will check the unit test code and add to call the clear() .

  12. MarcoFalke commented at 4:49 PM on February 5, 2019: member

    The tests are passing without the clear(), but I guess the state might be dirty (haven't actually checked) and future tests might break unexpectedly.

  13. AkioNak commented at 2:50 PM on February 6, 2019: contributor

    @promag @MarcoFalke Addressed.

    Both CI checks have failed:

    Appveyou -> Many linker error occurred. they are almost unresolved external symbols. but now I don't know what's wrong. https://ci.appveyor.com/project/DrahtBot/bitcoin/builds/22165173

    Travis CI -> The Compile time was over 25min for each failed jobs. I think it is not related to this change. https://travis-ci.org/bitcoin/bitcoin/builds/489501276?utm_source=github_status&utm_medium=notification


    edited: All checks have passed. Thanks for someone who restart them.

  14. in src/init.cpp:819 in cb592801da outdated
     815 | @@ -816,7 +816,7 @@ void InitParameterInteraction()
     816 |  
     817 |      // Warn if unrecognized section name are present in the config file.
     818 |      for (const auto& section : gArgs.GetUnrecognizedSections()) {
     819 | -        InitWarning(strprintf(_("Section [%s] is not recognized."), section));
     820 | +        InitWarning(strprintf(_("%s:%i:Section [%s] is not recognized."), section.file, section.line, section.name));
    


    laanwj commented at 1:49 PM on February 12, 2019:

    Would it make sense to move the %s:%i out of the translation message to keep it the same? The translators aren't going to understand that part anyway.


    AkioNak commented at 3:52 AM on February 13, 2019:

    @laanwj Thank you for your review. Addressed.

  15. in src/util/system.h:162 in 53b7a25961 outdated
     156 | @@ -150,9 +157,9 @@ class ArgsManager
     157 |      std::string m_network GUARDED_BY(cs_args);
     158 |      std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
     159 |      std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
     160 | -    std::set<std::string> m_config_sections GUARDED_BY(cs_args);
     161 | +    std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);
     162 |  
     163 | -    NODISCARD bool ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys = false);
     164 | +    NODISCARD bool ReadConfigStream(std::istream& stream, const std::string& label, std::string& error, bool ignore_invalid_keys = false);
    


    promag commented at 3:46 PM on February 15, 2019:

    Why is the argument called label when in the SectionInfo it's file? I'd name it filepath.


    AkioNak commented at 8:00 AM on February 18, 2019:

    I thought it might not only be a file stream. (unit test uses std::istringstream). But now I agree that filepath is better than label. Fixed.

  16. in src/util/system.h:135 in 53b7a25961 outdated
     129 | @@ -130,6 +130,13 @@ enum class OptionsCategory {
     130 |      HIDDEN // Always the last option to avoid printing these in the help
     131 |  };
     132 |  
     133 | +struct SectionInfo
     134 | +{
     135 | +    std::string name;
    


    promag commented at 3:48 PM on February 15, 2019:

    nit, I think these should have m_ prefix? Developer notes mentions:

    - Class member variables have a `m_` prefix.

    AkioNak commented at 8:01 AM on February 18, 2019:

    Thanks. Fixed.

  17. in src/util/system.cpp:802 in 53b7a25961 outdated
     798 | @@ -803,7 +799,7 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
     799 |          if (!str.empty()) {
     800 |              if (*str.begin() == '[' && *str.rbegin() == ']') {
     801 |                  const std::string section = str.substr(1, str.size() - 2);
     802 | -                sections.insert(section);
     803 | +                sections.push_back(SectionInfo{section, label, linenr});
    


    promag commented at 3:51 PM on February 15, 2019:

    Could use emplace_back?


    AkioNak commented at 8:04 AM on February 18, 2019:

    Thanks. Addressed.

  18. in src/util/system.cpp:366 in 53b7a25961 outdated
     369 | -    std::set_difference(
     370 | -        m_config_sections.begin(), m_config_sections.end(),
     371 | -        available_sections.begin(), available_sections.end(),
     372 | -        std::inserter(diff, diff.end()));
     373 | -    return diff;
     374 | +    auto u = m_config_sections;
    


    promag commented at 4:00 PM on February 15, 2019:

    Use better variable name. Maybe also drop auto.


    AkioNak commented at 8:12 AM on February 18, 2019:

    @promag I cannot drop auto simply. I am happy if you explain a little more.


    promag commented at 4:18 PM on February 18, 2019:

    I mean, could have explicit type.


    AkioNak commented at 2:55 AM on February 19, 2019:

    Thanks. I understand. Addressed.

  19. in src/util/system.cpp:367 in 53b7a25961 outdated
     370 | -        m_config_sections.begin(), m_config_sections.end(),
     371 | -        available_sections.begin(), available_sections.end(),
     372 | -        std::inserter(diff, diff.end()));
     373 | -    return diff;
     374 | +    auto u = m_config_sections;
     375 | +    u.remove_if([](const SectionInfo& s){ return available_sections.find(s.name) != available_sections.end(); });
    


    promag commented at 4:00 PM on February 15, 2019:

    Use better variable name.


    AkioNak commented at 8:06 AM on February 18, 2019:

    Fixed : parameter for lambda function.

  20. in src/util/system.cpp:816 in 53b7a25961 outdated
     811 | @@ -816,8 +812,8 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
     812 |                      return false;
     813 |                  }
     814 |                  options.emplace_back(name, value);
     815 | -                if ((pos = name.rfind('.')) != std::string::npos) {
     816 | -                    sections.insert(name.substr(0, pos));
     817 | +                if ((pos = name.rfind('.')) != std::string::npos && prefix.length() <= pos) {
     818 | +                    sections.push_back(SectionInfo{name.substr(0, pos), label, linenr});
    


    promag commented at 4:01 PM on February 15, 2019:

    Also emplace_back.


    AkioNak commented at 8:04 AM on February 18, 2019:

    Thanks. Addressed.

  21. promag commented at 4:01 PM on February 15, 2019: member

    utACK 53b7a25. Needs squash.

  22. AkioNak force-pushed on Feb 18, 2019
  23. MarcoFalke commented at 4:06 PM on February 18, 2019: member

    re-utACK 6fffaec0e72c21

  24. promag commented at 4:18 PM on February 18, 2019: member

    utACK 6fffaec0e72c214d538ef50c337950b4c92ccd57, will test.

  25. Fix lack of warning of unrecognized section names
    1. Fix lack of warning by collecting all section names by moving
       m_config_sections.clear() to ArgsManager::ReadConfigFiles().
    2. Add info(file name, line number) to warning message.
    3. Add a test code to confirm this situation.
    3. Do clear() in ReadConfigString().
    1a7ba84e11
  26. AkioNak force-pushed on Feb 19, 2019
  27. MarcoFalke commented at 7:13 PM on February 19, 2019: member

    re-utACK 1a7ba84e11

  28. promag commented at 5:26 PM on February 23, 2019: member

    Tested ACK 1a7ba84.

  29. MarcoFalke added this to the milestone 0.19.0 on Feb 23, 2019
  30. MarcoFalke referenced this in commit 789b0bbf2a on Mar 2, 2019
  31. MarcoFalke merged this on Mar 2, 2019
  32. MarcoFalke closed this on Mar 2, 2019

  33. AkioNak deleted the branch on Mar 13, 2019
  34. deadalnix referenced this in commit adce4f2b6d on Apr 17, 2020
  35. ftrader referenced this in commit 895297060a on Aug 17, 2020
  36. Munkybooty referenced this in commit ef6a5e8545 on Sep 8, 2021
  37. christiancfifi referenced this in commit ac500d4101 on Oct 3, 2021
  38. vijaydasmp referenced this in commit dc25f37e70 on Oct 12, 2021
  39. vijaydasmp referenced this in commit 029b62851b on Oct 14, 2021
  40. vijaydasmp referenced this in commit cbefc8240b on Oct 14, 2021
  41. vijaydasmp referenced this in commit 36c36aaee1 on Oct 16, 2021
  42. PastaPastaPasta referenced this in commit 6e32a464f5 on Oct 21, 2021
  43. pravblockc referenced this in commit 8df28994d8 on Nov 18, 2021
  44. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me