diff options
author | Jonathan Schoeller <jonathan.schoeller@rea-group.com> | 2020-06-01 18:05:15 +1000 |
---|---|---|
committer | Jonathan Schoeller <jonathan.schoeller@rea-group.com> | 2020-06-02 06:20:04 +1000 |
commit | d15db4b1fc988736b08c092d000ca1d1ff686975 (patch) | |
tree | 9b223f81d2a0deca3d8082216a00ddb13608d93c /src | |
parent | 091cc4b94e009f7140493cd37798d447c6881e5e (diff) |
refactor: Fix unreachable code in init arg checks
Building with -Wunreachable-code-loop-increment causes a warning
due to always returning on the first iteration of the loop that
outputs errors on invalid args.
Collect all errors, and output them in a single error message
after the loop completes, resolving the warning and avoiding
popup hell by outputting a seperate message for each error.
Diffstat (limited to 'src')
-rw-r--r-- | src/init.cpp | 16 | ||||
-rw-r--r-- | src/util/translation.h | 5 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/init.cpp b/src/init.cpp index 37e6251295..0ff89eb816 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -964,17 +964,27 @@ bool AppInitParameterInteraction() // also see: InitParameterInteraction() - // Warn if network-specific options (-addnode, -connect, etc) are + // Error if network-specific options (-addnode, -connect, etc) are // specified in default section of config file, but not overridden // on the command line or in this network's section of the config file. std::string network = gArgs.GetChainName(); + bilingual_str errors; for (const auto& arg : gArgs.GetUnsuitableSectionOnlyArgs()) { - return InitError(strprintf(_("Config setting for %s only applied on %s network when in [%s] section."), arg, network, network)); + errors += strprintf(_("Config setting for %s only applied on %s network when in [%s] section.") + Untranslated("\n"), arg, network, network); + } + + if (!errors.empty()) { + return InitError(errors); } // Warn if unrecognized section name are present in the config file. + bilingual_str warnings; for (const auto& section : gArgs.GetUnrecognizedSections()) { - InitWarning(strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized."), section.m_file, section.m_line, section.m_name)); + warnings += strprintf(Untranslated("%s:%i ") + _("Section [%s] is not recognized.") + Untranslated("\n"), section.m_file, section.m_line, section.m_name); + } + + if (!warnings.empty()) { + InitWarning(warnings); } if (!fs::is_directory(GetBlocksDir())) { diff --git a/src/util/translation.h b/src/util/translation.h index 268bcf30a7..695d6dac96 100644 --- a/src/util/translation.h +++ b/src/util/translation.h @@ -23,6 +23,11 @@ struct bilingual_str { translated += rhs.translated; return *this; } + + bool empty() const + { + return original.empty(); + } }; inline bilingual_str operator+(bilingual_str lhs, const bilingual_str& rhs) |