-
Notifications
You must be signed in to change notification settings - Fork 354
Prompt to reset settings when settings.json cannot be read #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,58 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans | |
| QApplication::installTranslator(&translator); | ||
| } | ||
|
|
||
| static std::string JoinErrors(const std::vector<std::string>& errors) | ||
| { | ||
| return Join(errors, "\n", [](const std::string& error) { return "- " + error; }); | ||
| } | ||
|
|
||
| static bool InitSettings() | ||
| { | ||
| if (!gArgs.GetSettingsPath()) { | ||
| return true; // Do nothing if settings file disabled. | ||
| } | ||
|
|
||
| std::vector<std::string> errors; | ||
| if (!gArgs.ReadSettingsFile(&errors)) { | ||
| bilingual_str error = _("Settings file could not be read"); | ||
| InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors)))); | ||
|
|
||
| QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Reset | QMessageBox::Abort); | ||
| /*: Explanatory text shown on startup when the settings file cannot be read. | ||
| Prompts user to make a choice between resetting or aborting. */ | ||
| messagebox.setInformativeText(QObject::tr("Do you want to reset settings to default values, or to abort without making changes?")); | ||
| messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors))); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually, we use a detailed text to show untranslated error messages to users for convenient googling and referencing (see bitcoin/bitcoin#16224). Now it only contains a list of errors. Could an untranslated error message be added here as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: #379 (comment)
Just to clarify what's being discussed, On the prefixing, I do think it would be reasonable for a followup PR to append
|
||
| messagebox.setTextFormat(Qt::PlainText); | ||
| messagebox.setDefaultButton(QMessageBox::Reset); | ||
| switch (messagebox.exec()) { | ||
| case QMessageBox::Reset: | ||
| break; | ||
| case QMessageBox::Abort: | ||
| return false; | ||
| default: | ||
| assert(false); | ||
| } | ||
| } | ||
|
|
||
| errors.clear(); | ||
| if (!gArgs.WriteSettingsFile(&errors)) { | ||
| bilingual_str error = _("Settings file could not be written"); | ||
| InitError(Untranslated(strprintf("%s:\n%s\n", error.original, JoinErrors(errors)))); | ||
|
|
||
| QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error.translated)), QMessageBox::Ok); | ||
| /*: Explanatory text shown on startup when the settings file could not be written. | ||
| Prompts user to check that we have the ability to write to the file. | ||
| Explains that the user has the option of running without a settings file.*/ | ||
| messagebox.setInformativeText(QObject::tr("A fatal error occured. Check that settings file is writable, or try running with -nosettings.")); | ||
|
ryanofsky marked this conversation as resolved.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: occured ==> occurred Addressed in bitcoin/bitcoin#22653. |
||
| messagebox.setDetailedText(QString::fromStdString(JoinErrors(errors))); | ||
| messagebox.setTextFormat(Qt::PlainText); | ||
| messagebox.setDefaultButton(QMessageBox::Ok); | ||
| messagebox.exec(); | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /* qDebug() message handler --> debug.log */ | ||
| void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString &msg) | ||
| { | ||
|
|
@@ -569,9 +621,8 @@ int GuiMain(int argc, char* argv[]) | |
| // Parse URIs on command line -- this can affect Params() | ||
| PaymentServer::ipcParseCommandLine(argc, argv); | ||
| #endif | ||
| if (!gArgs.InitSettings(error)) { | ||
| InitError(Untranslated(error)); | ||
| QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error initializing settings: %1").arg(QString::fromStdString(error))); | ||
|
|
||
| if (!InitSettings()) { | ||
| return EXIT_FAILURE; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could add a translator comment:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #379 (comment)
Added, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the logic to actually reset the settings to defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happens implicitly because if reading the settings file fails, the file that is written on line 181 will be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if it fails part way into reading the settings, won't the ones it already read remain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: #379 (comment)
To my surprise, it is actually technically possible for this to happen! And it needs to be fixed outside the GUI code so I filed a bug in the main repo bitcoin/bitcoin#22638. Practically speaking, the scenario where this would happen is nearly impossible and if it did happen, the effect would just be settings kept instead of discarded. So I think there's no need for this PR to be held up by the bug, but it is a good catch!