Skip to content

Commit c361df9

Browse files
committed
scripted-diff: Remove double newlines after some init errors
Some InitError calls had trailing \n characters, causing double newlines in error output. After this change InitError calls consistently output one newline instead of two. Appearance of messages in the GUI does not seem to be affected. Can be tested with: src/bitcoind -regtest -datadir=noexist src/qt/bitcoin-qt -regtest -datadir=noexist -BEGIN VERIFY SCRIPT- git grep -l InitError src/ | xargs sed -i 's/\(InitError(.*\)\\n"/\1"/' -END VERIFY SCRIPT-
1 parent cb40639 commit c361df9

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/bitcoind.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
120120
SetupServerArgs(args);
121121
std::string error;
122122
if (!args.ParseParameters(argc, argv, error)) {
123-
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error)));
123+
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s", error)));
124124
}
125125

126126
// Process help and version before taking care about datadir
@@ -151,22 +151,22 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
151151
try
152152
{
153153
if (!CheckDataDirOption(args)) {
154-
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""))));
154+
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.", args.GetArg("-datadir", ""))));
155155
}
156156
if (!args.ReadConfigFiles(error, true)) {
157-
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
157+
return InitError(Untranslated(strprintf("Error reading configuration file: %s", error)));
158158
}
159159
// Check for chain settings (Params() calls are only valid after this clause)
160160
try {
161161
SelectParams(args.GetChainName());
162162
} catch (const std::exception& e) {
163-
return InitError(Untranslated(strprintf("%s\n", e.what())));
163+
return InitError(Untranslated(strprintf("%s", e.what())));
164164
}
165165

166166
// Error out when loose non-argument tokens are encountered on command line
167167
for (int i = 1; i < argc; i++) {
168168
if (!IsSwitchChar(argv[i][0])) {
169-
return InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i])));
169+
return InitError(Untranslated(strprintf("Command line contains unexpected token '%s', see bitcoind -h for a list of options.", argv[i])));
170170
}
171171
}
172172

@@ -210,7 +210,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
210210
}
211211
break;
212212
case -1: // Error happened.
213-
return InitError(Untranslated(strprintf("fork_daemon() failed: %s\n", SysErrorString(errno))));
213+
return InitError(Untranslated(strprintf("fork_daemon() failed: %s", SysErrorString(errno))));
214214
default: { // Parent: wait and exit.
215215
int token = daemon_ep.TokenRead();
216216
if (token) { // Success
@@ -222,7 +222,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
222222
}
223223
}
224224
#else
225-
return InitError(Untranslated("-daemon is not supported on this operating system\n"));
225+
return InitError(Untranslated("-daemon is not supported on this operating system"));
226226
#endif // HAVE_DECL_FORK
227227
}
228228
// Lock data directory after daemonization

src/qt/bitcoin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static bool InitSettings()
176176
if (!gArgs.ReadSettingsFile(&errors)) {
177177
std::string error = QT_TRANSLATE_NOOP("bitcoin-core", "Settings file could not be read");
178178
std::string error_translated = QCoreApplication::translate("bitcoin-core", error.c_str()).toStdString();
179-
InitError(Untranslated(strprintf("%s:\n%s\n", error, MakeUnorderedList(errors))));
179+
InitError(Untranslated(strprintf("%s:\n%s", error, MakeUnorderedList(errors))));
180180

181181
QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error_translated)), QMessageBox::Reset | QMessageBox::Abort);
182182
/*: Explanatory text shown on startup when the settings file cannot be read.
@@ -199,7 +199,7 @@ static bool InitSettings()
199199
if (!gArgs.WriteSettingsFile(&errors)) {
200200
std::string error = QT_TRANSLATE_NOOP("bitcoin-core", "Settings file could not be written");
201201
std::string error_translated = QCoreApplication::translate("bitcoin-core", error.c_str()).toStdString();
202-
InitError(Untranslated(strprintf("%s:\n%s\n", error, MakeUnorderedList(errors))));
202+
InitError(Untranslated(strprintf("%s:\n%s", error, MakeUnorderedList(errors))));
203203

204204
QMessageBox messagebox(QMessageBox::Critical, PACKAGE_NAME, QString::fromStdString(strprintf("%s.", error_translated)), QMessageBox::Ok);
205205
/*: Explanatory text shown on startup when the settings file could not be written.
@@ -546,7 +546,7 @@ int GuiMain(int argc, char* argv[])
546546
SetupUIArgs(gArgs);
547547
std::string error;
548548
if (!gArgs.ParseParameters(argc, argv, error)) {
549-
InitError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));
549+
InitError(strprintf(Untranslated("Error parsing command line arguments: %s"), error));
550550
// Create a message box, because the gui has neither been created nor has subscribed to core signals
551551
QMessageBox::critical(nullptr, PACKAGE_NAME,
552552
// message cannot be translated because translations have not been initialized
@@ -589,7 +589,7 @@ int GuiMain(int argc, char* argv[])
589589

590590
/// 6a. Determine availability of data directory
591591
if (!CheckDataDirOption(gArgs)) {
592-
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
592+
InitError(strprintf(Untranslated("Specified data directory \"%s\" does not exist."), gArgs.GetArg("-datadir", "")));
593593
QMessageBox::critical(nullptr, PACKAGE_NAME,
594594
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
595595
return EXIT_FAILURE;
@@ -598,7 +598,7 @@ int GuiMain(int argc, char* argv[])
598598
/// 6b. Parse bitcoin.conf
599599
/// - Do not call gArgs.GetDataDirNet() before this step finishes
600600
if (!gArgs.ReadConfigFiles(error, true)) {
601-
InitError(strprintf(Untranslated("Error reading configuration file: %s\n"), error));
601+
InitError(strprintf(Untranslated("Error reading configuration file: %s"), error));
602602
QMessageBox::critical(nullptr, PACKAGE_NAME,
603603
QObject::tr("Error: Cannot parse configuration file: %1.").arg(QString::fromStdString(error)));
604604
return EXIT_FAILURE;
@@ -613,7 +613,7 @@ int GuiMain(int argc, char* argv[])
613613
// Check for chain settings (Params() calls are only valid after this clause)
614614
SelectParams(gArgs.GetChainName());
615615
} catch(std::exception &e) {
616-
InitError(Untranslated(strprintf("%s\n", e.what())));
616+
InitError(Untranslated(strprintf("%s", e.what())));
617617
QMessageBox::critical(nullptr, PACKAGE_NAME, QObject::tr("Error: %1").arg(e.what()));
618618
return EXIT_FAILURE;
619619
}

0 commit comments

Comments
 (0)