Skip to content

Commit cf310da

Browse files
committed
qml: Handle initialization errors
1 parent 44e97a0 commit cf310da

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

src/qml/bitcoin.cpp

+32-8
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,55 @@ int QmlGuiMain(int argc, char* argv[])
5656

5757
auto handler_message_box = ::uiInterface.ThreadSafeMessageBox_connect(InitErrorMessageBox);
5858

59-
// Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
59+
NodeContext node_context;
60+
61+
/// Parse command-line options. We do this after qt in order to show an error if there are problems parsing these.
62+
node_context.args = &gArgs;
6063
SetupServerArgs(gArgs);
6164
SetupUIArgs(gArgs);
6265
std::string error;
6366
if (!gArgs.ParseParameters(argc, argv, error)) {
64-
InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
67+
InitError(strprintf(Untranslated("Cannot parse command line arguments: %s\n"), error));
68+
return EXIT_FAILURE;
69+
}
70+
71+
/// Determine availability of data directory.
72+
if (!CheckDataDirOption()) {
73+
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
6574
return EXIT_FAILURE;
6675
}
6776

68-
CheckDataDirOption();
77+
/// Read and parse bitcoin.conf file.
78+
if (!gArgs.ReadConfigFiles(error, true)) {
79+
InitError(strprintf(Untranslated("Cannot parse configuration file: %s\n"), error));
80+
return EXIT_FAILURE;
81+
}
6982

70-
gArgs.ReadConfigFiles(error, true);
83+
/// Check for chain settings (Params() calls are only valid after this clause).
84+
try {
85+
SelectParams(gArgs.GetChainName());
86+
} catch(std::exception &e) {
87+
InitError(Untranslated(strprintf("%s\n", e.what())));
88+
return EXIT_FAILURE;
89+
}
7190

72-
SelectParams(gArgs.GetChainName());
91+
/// Read and parse settings.json file.
92+
if (!gArgs.InitSettings(error)) {
93+
InitError(Untranslated(error));
94+
return EXIT_FAILURE;
95+
}
7396

7497
// Default printtoconsole to false for the GUI. GUI programs should not
7598
// print to the console unnecessarily.
7699
gArgs.SoftSetBoolArg("-printtoconsole", false);
77100
InitLogging(gArgs);
78101
InitParameterInteraction(gArgs);
79102

80-
NodeContext node_context;
81-
node_context.args = &gArgs;
82103
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode(&node_context);
83-
node->baseInitialize();
104+
if (!node->baseInitialize()) {
105+
// A dialog with detailed error will have been shown by InitError().
106+
return EXIT_FAILURE;
107+
}
84108

85109
handler_message_box.disconnect();
86110

0 commit comments

Comments
 (0)