aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2024-01-09 09:54:49 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2024-01-22 10:50:03 -0300
commit966f5de99a9f5da05c91378ad1e8ea8ed37ac3b3 (patch)
tree8d1d6abefc908ec6dd83391553477f6349b02cc1
parent03752444cd54df05a731557968d5a9f33a55c55c (diff)
downloadbitcoin-966f5de99a9f5da05c91378ad1e8ea8ed37ac3b3.tar.xz
init: improve corrupted/empty settings file error msg
The preceding "Unable to parse settings file" message lacked the necessary detail and guidance for users on what steps to take next in order to resolve the startup error. Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
-rw-r--r--src/common/settings.cpp4
-rw-r--r--src/test/settings_tests.cpp4
-rwxr-xr-xtest/functional/feature_settings.py2
3 files changed, 7 insertions, 3 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 5761e8b321..cbf794a7c6 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -81,7 +81,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;
}
diff --git a/src/test/settings_tests.cpp b/src/test/settings_tests.cpp
index fa8ceb8dd6..41190b3579 100644
--- a/src/test/settings_tests.cpp
+++ b/src/test/settings_tests.cpp
@@ -99,7 +99,9 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
// Check invalid json not allowed
WriteText(path, R"(invalid json)");
BOOST_CHECK(!common::ReadSettings(path, values, errors));
- std::vector<std::string> fail_parse = {strprintf("Unable to parse settings file %s", fs::PathToString(path))};
+ std::vector<std::string> fail_parse = {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))};
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), fail_parse.begin(), fail_parse.end());
}
diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py
index 1bacdd447a..4175699152 100755
--- a/test/functional/feature_settings.py
+++ b/test/functional/feature_settings.py
@@ -53,7 +53,7 @@ class SettingsTest(BitcoinTestFramework):
# Test invalid json
with settings.open("w") as fp:
fp.write("invalid json")
- node.assert_start_raises_init_error(expected_msg='Unable to parse settings file', match=ErrorMatch.PARTIAL_REGEX)
+ node.assert_start_raises_init_error(expected_msg='does not contain valid JSON. This is probably caused by disk corruption or a crash', match=ErrorMatch.PARTIAL_REGEX)
# Test invalid json object
with settings.open("w") as fp: