Credit to @luke-jr for helping uncovering this bug https://github.com/bitcoin-core/gui/pull/379#discussion_r680408927

This bug has no user-visible effects currently, but combined with PR [bitcoin-core/gui#379](https://github.com/bitcoin-core/gui/pull/379) and a corrupt `settings.json` file that is corrupted specifically by specifying the same JSON keys multiple times, it can cause some dialog text added in that PR to be misleading. This is a basically an impossible-to-hit rube goldberg bug, but is only fixable at the util level not the GUI level, so I'm tracking this outside the GUI repository.

Simplest fix would be to just change `ReadSettingsFile` to call `rw_settings.clear()` on error. It would also be nice to add a unit test for the regression.

Code path that triggers this is:

https://github.com/bitcoin/bitcoin/blob/d67330d11245b11fbdd5e2dd5343ee451186931e/src/util/system.cpp#L548
https://github.com/bitcoin/bitcoin/blob/d67330d11245b11fbdd5e2dd5343ee451186931e/src/util/settings.cpp#L89
https://github.com/bitcoin/bitcoin/blob/d67330d11245b11fbdd5e2dd5343ee451186931e/src/util/settings.cpp#L92
const std::string& section,
    const std::string& name,
    bool ignore_default_section_config,
    bool ignore_nonpersistent,
    bool get_chain_name)
{
    SettingsValue result;
    bool done = false; 
    MergeSettings(settings, section, name, [&](SettingsSpan span, Source source) {
        
        
        
        
        const bool never_ignore_negated_setting = span.last_negated();
        
        
        
        
        
        const bool reverse_precedence =
            (source == Source::CONFIG_FILE_NETWORK_SECTION || source == Source::CONFIG_FILE_DEFAULT_SECTION) &&
            !get_chain_name;
        
        
        
        
        
        const bool skip_negated_command_line = get_chain_name;
        if (done) return;