aboutsummaryrefslogtreecommitdiff
path: root/src/common/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/settings.cpp')
-rw-r--r--src/common/settings.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 5761e8b321..c1520dacd2 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -4,6 +4,8 @@
#include <common/settings.h>
+#include <config/bitcoin-config.h> // IWYU pragma: keep
+
#include <tinyformat.h>
#include <univalue.h>
#include <util/fs.h>
@@ -27,6 +29,9 @@ enum class Source {
CONFIG_FILE_DEFAULT_SECTION
};
+// Json object key for the auto-generated warning comment
+const std::string SETTINGS_WARN_MSG_KEY{"_warning_"};
+
//! Merge settings from multiple sources in precedence order:
//! Forced config > command line > read-write settings file > config file network-specific section > config file default section
//!
@@ -81,7 +86,9 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
SettingsValue in;
if (!in.read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
- errors.emplace_back(strprintf("Unable to parse settings file %s", fs::PathToString(path)));
+ errors.emplace_back(strprintf("Settings file %s does not contain valid JSON. This is probably caused by disk corruption or a crash, "
+ "and can be fixed by removing the file, which will reset settings to default values.",
+ fs::PathToString(path)));
return false;
}
@@ -106,6 +113,10 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
break;
}
}
+
+ // Remove auto-generated warning comment from the accessible settings.
+ values.erase(SETTINGS_WARN_MSG_KEY);
+
return errors.empty();
}
@@ -114,6 +125,10 @@ bool WriteSettings(const fs::path& path,
std::vector<std::string>& errors)
{
SettingsValue out(SettingsValue::VOBJ);
+ // Add auto-generated warning comment
+ out.pushKV(SETTINGS_WARN_MSG_KEY, strprintf("This file is automatically generated and updated by %s. Please do not edit this file while the node "
+ "is running, as any changes might be ignored or overwritten.", PACKAGE_NAME));
+ // Push settings values
for (const auto& value : values) {
out.pushKVEnd(value.first, value.second);
}