Skip to content

Commit 966f5de

Browse files
furszyryanofsky
andcommitted
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>
1 parent 0375244 commit 966f5de

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/common/settings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ bool ReadSettings(const fs::path& path, std::map<std::string, SettingsValue>& va
8181

8282
SettingsValue in;
8383
if (!in.read(std::string{std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()})) {
84-
errors.emplace_back(strprintf("Unable to parse settings file %s", fs::PathToString(path)));
84+
errors.emplace_back(strprintf("Settings file %s does not contain valid JSON. This is probably caused by disk corruption or a crash, "
85+
"and can be fixed by removing the file, which will reset settings to default values.",
86+
fs::PathToString(path)));
8587
return false;
8688
}
8789

src/test/settings_tests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ BOOST_AUTO_TEST_CASE(ReadWrite)
9999
// Check invalid json not allowed
100100
WriteText(path, R"(invalid json)");
101101
BOOST_CHECK(!common::ReadSettings(path, values, errors));
102-
std::vector<std::string> fail_parse = {strprintf("Unable to parse settings file %s", fs::PathToString(path))};
102+
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, "
103+
"and can be fixed by removing the file, which will reset settings to default values.",
104+
fs::PathToString(path))};
103105
BOOST_CHECK_EQUAL_COLLECTIONS(errors.begin(), errors.end(), fail_parse.begin(), fail_parse.end());
104106
}
105107

test/functional/feature_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def run_test(self):
5353
# Test invalid json
5454
with settings.open("w") as fp:
5555
fp.write("invalid json")
56-
node.assert_start_raises_init_error(expected_msg='Unable to parse settings file', match=ErrorMatch.PARTIAL_REGEX)
56+
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)
5757

5858
# Test invalid json object
5959
with settings.open("w") as fp:

0 commit comments

Comments
 (0)