Skip to content

Commit 332c613

Browse files
committed
Merge #15894: Remove duplicated "Error: " prefix in logs
f724f31 Make AbortNode() aware of MSG_NOPREFIX flag (Hennadii Stepanov) 96fd4ee Add MSG_NOPREFIX flag for user messages (Hennadii Stepanov) f0641f2 Prepend the error/warning prefix for GUI messages (Hennadii Stepanov) Pull request description: The "Error" prefix/title is set already in the next functions: - `noui_ThreadSafeMessageBox()`https://github.com/bitcoin/bitcoin/blob/2068f089c8b7b90eb4557d3f67ea0f0ed2059a23/src/noui.cpp#L17 - `ThreadSafeMessageBox()`https://github.com/bitcoin/bitcoin/blob/a720a983015c9ef8cc814c16a5b9ef6379695817/src/qt/bitcoingui.cpp#L1351 Currently on master: ![Screenshot from 2019-04-25 22-08-54](https://user-images.githubusercontent.com/32963518/56763092-25ee8280-67aa-11e9-86c8-6a029dd9ab08.png) With this PR: ![Screenshot from 2019-04-25 22-26-36](https://user-images.githubusercontent.com/32963518/56763107-30108100-67aa-11e9-9021-683cbd7e2aaa.png) ACKs for top commit: laanwj: concept and code-review ACK f724f31 Tree-SHA512: 218a179b81cc2ac64239d833c02b4c4d4da9b976728a2dcd645966726c4c660b6f1fe43aa28f33d1cb566785a4329e7f93bf5a502bf202316db79d2ff5fce0f8
2 parents c52776e + f724f31 commit 332c613

File tree

5 files changed

+52
-41
lines changed

5 files changed

+52
-41
lines changed

src/noui.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& ca
1818
{
1919
bool fSecure = style & CClientUIInterface::SECURE;
2020
style &= ~CClientUIInterface::SECURE;
21+
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
22+
style &= ~CClientUIInterface::MSG_NOPREFIX;
2123

2224
std::string strCaption;
23-
// Check for usage of predefined caption
24-
switch (style) {
25-
case CClientUIInterface::MSG_ERROR:
26-
strCaption += _("Error");
27-
break;
28-
case CClientUIInterface::MSG_WARNING:
29-
strCaption += _("Warning");
30-
break;
31-
case CClientUIInterface::MSG_INFORMATION:
32-
strCaption += _("Information");
33-
break;
34-
default:
35-
strCaption += caption; // Use supplied caption (can be empty)
25+
if (prefix) {
26+
switch (style) {
27+
case CClientUIInterface::MSG_ERROR:
28+
strCaption = "Error: ";
29+
break;
30+
case CClientUIInterface::MSG_WARNING:
31+
strCaption = "Warning: ";
32+
break;
33+
case CClientUIInterface::MSG_INFORMATION:
34+
strCaption = "Information: ";
35+
break;
36+
default:
37+
strCaption = caption + ": "; // Use supplied caption (can be empty)
38+
}
3639
}
3740

38-
if (!fSecure)
39-
LogPrintf("%s: %s\n", strCaption, message);
40-
tfm::format(std::cerr, "%s: %s\n", strCaption.c_str(), message.c_str());
41+
if (!fSecure) {
42+
LogPrintf("%s%s\n", strCaption, message);
43+
}
44+
tfm::format(std::cerr, "%s%s\n", strCaption.c_str(), message.c_str());
4145
return false;
4246
}
4347

src/qt/bitcoingui.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,49 +1039,51 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
10391039
progressBar->setToolTip(tooltip);
10401040
}
10411041

1042-
void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
1042+
void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret)
10431043
{
1044-
QString strTitle = tr("Bitcoin"); // default title
1044+
// Default title. On macOS, the window title is ignored (as required by the macOS Guidelines).
1045+
QString strTitle{PACKAGE_NAME};
10451046
// Default to information icon
10461047
int nMBoxIcon = QMessageBox::Information;
10471048
int nNotifyIcon = Notificator::Information;
10481049

1049-
QString msgType;
1050+
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
1051+
style &= ~CClientUIInterface::MSG_NOPREFIX;
10501052

1051-
// Prefer supplied title over style based title
1053+
QString msgType;
10521054
if (!title.isEmpty()) {
10531055
msgType = title;
1054-
}
1055-
else {
1056+
} else {
10561057
switch (style) {
10571058
case CClientUIInterface::MSG_ERROR:
10581059
msgType = tr("Error");
1060+
if (prefix) message = tr("Error: %1").arg(message);
10591061
break;
10601062
case CClientUIInterface::MSG_WARNING:
10611063
msgType = tr("Warning");
1064+
if (prefix) message = tr("Warning: %1").arg(message);
10621065
break;
10631066
case CClientUIInterface::MSG_INFORMATION:
10641067
msgType = tr("Information");
1068+
// No need to prepend the prefix here.
10651069
break;
10661070
default:
10671071
break;
10681072
}
10691073
}
1070-
// Append title to "Bitcoin - "
1071-
if (!msgType.isEmpty())
1074+
1075+
if (!msgType.isEmpty()) {
10721076
strTitle += " - " + msgType;
1077+
}
10731078

1074-
// Check for error/warning icon
10751079
if (style & CClientUIInterface::ICON_ERROR) {
10761080
nMBoxIcon = QMessageBox::Critical;
10771081
nNotifyIcon = Notificator::Critical;
1078-
}
1079-
else if (style & CClientUIInterface::ICON_WARNING) {
1082+
} else if (style & CClientUIInterface::ICON_WARNING) {
10801083
nMBoxIcon = QMessageBox::Warning;
10811084
nNotifyIcon = Notificator::Warning;
10821085
}
10831086

1084-
// Display message
10851087
if (style & CClientUIInterface::MODAL) {
10861088
// Check for buttons, use OK as default, if none was supplied
10871089
QMessageBox::StandardButton buttons;
@@ -1094,9 +1096,9 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
10941096
int r = mBox.exec();
10951097
if (ret != nullptr)
10961098
*ret = r == QMessageBox::Ok;
1097-
}
1098-
else
1099+
} else {
10991100
notificator->notify(static_cast<Notificator::Class>(nNotifyIcon), strTitle, message);
1101+
}
11001102
}
11011103

11021104
void BitcoinGUI::changeEvent(QEvent *e)

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public Q_SLOTS:
220220
@see CClientUIInterface::MessageBoxFlags
221221
@param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only)
222222
*/
223-
void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
223+
void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr);
224224

225225
#ifdef ENABLE_WALLET
226226
void setCurrentWallet(WalletModel* wallet_model);

src/ui_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class CClientUIInterface
6969
/** Force blocking, modal message box dialog (not just OS notification) */
7070
MODAL = 0x10000000U,
7171

72+
/** Do not prepend error/warning prefix */
73+
MSG_NOPREFIX = 0x20000000U,
74+
7275
/** Do not print contents of message to debug log */
7376
SECURE = 0x40000000U,
7477

src/validation.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,20 +1374,22 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
13741374
}
13751375

13761376
/** Abort with a message */
1377-
static bool AbortNode(const std::string& strMessage, const std::string& userMessage="")
1377+
static bool AbortNode(const std::string& strMessage, const std::string& userMessage = "", unsigned int prefix = 0)
13781378
{
13791379
SetMiscWarning(strMessage);
13801380
LogPrintf("*** %s\n", strMessage);
1381-
uiInterface.ThreadSafeMessageBox(
1382-
userMessage.empty() ? _("Error: A fatal internal error occurred, see debug.log for details") : userMessage,
1383-
"", CClientUIInterface::MSG_ERROR);
1381+
if (!userMessage.empty()) {
1382+
uiInterface.ThreadSafeMessageBox(userMessage, "", CClientUIInterface::MSG_ERROR | prefix);
1383+
} else {
1384+
uiInterface.ThreadSafeMessageBox(_("Error: A fatal internal error occurred, see debug.log for details"), "", CClientUIInterface::MSG_ERROR | CClientUIInterface::MSG_NOPREFIX);
1385+
}
13841386
StartShutdown();
13851387
return false;
13861388
}
13871389

1388-
static bool AbortNode(CValidationState& state, const std::string& strMessage, const std::string& userMessage="")
1390+
static bool AbortNode(CValidationState& state, const std::string& strMessage, const std::string& userMessage = "", unsigned int prefix = 0)
13891391
{
1390-
AbortNode(strMessage, userMessage);
1392+
AbortNode(strMessage, userMessage, prefix);
13911393
return state.Error(strMessage);
13921394
}
13931395

@@ -1998,7 +2000,7 @@ bool CChainState::FlushStateToDisk(
19982000
if (fDoFullFlush || fPeriodicWrite) {
19992001
// Depend on nMinDiskSpace to ensure we can write block index
20002002
if (!CheckDiskSpace(GetBlocksDir())) {
2001-
return AbortNode(state, "Disk space is low!", _("Error: Disk space is low!"));
2003+
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!"), CClientUIInterface::MSG_NOPREFIX);
20022004
}
20032005
// First make sure all block and undo data is flushed to disk.
20042006
FlushBlockFile();
@@ -2033,7 +2035,7 @@ bool CChainState::FlushStateToDisk(
20332035
// an overestimation, as most will delete an existing entry or
20342036
// overwrite one. Still, use a conservative safety factor of 2.
20352037
if (!CheckDiskSpace(GetDataDir(), 48 * 2 * 2 * pcoinsTip->GetCacheSize())) {
2036-
return AbortNode(state, "Disk space is low!", _("Error: Disk space is low!"));
2038+
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!"), CClientUIInterface::MSG_NOPREFIX);
20372039
}
20382040
// Flush the chainstate (which may refer to block index entries).
20392041
if (!pcoinsTip->Flush())
@@ -2899,7 +2901,7 @@ static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int n
28992901
bool out_of_space;
29002902
size_t bytes_allocated = BlockFileSeq().Allocate(pos, nAddSize, out_of_space);
29012903
if (out_of_space) {
2902-
return AbortNode("Disk space is low!", _("Error: Disk space is low!"));
2904+
return AbortNode("Disk space is too low!", _("Error: Disk space is too low!"), CClientUIInterface::MSG_NOPREFIX);
29032905
}
29042906
if (bytes_allocated != 0 && fPruneMode) {
29052907
fCheckForPruning = true;
@@ -2923,7 +2925,7 @@ static bool FindUndoPos(CValidationState &state, int nFile, FlatFilePos &pos, un
29232925
bool out_of_space;
29242926
size_t bytes_allocated = UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
29252927
if (out_of_space) {
2926-
return AbortNode(state, "Disk space is low!", _("Error: Disk space is low!"));
2928+
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!"), CClientUIInterface::MSG_NOPREFIX);
29272929
}
29282930
if (bytes_allocated != 0 && fPruneMode) {
29292931
fCheckForPruning = true;

0 commit comments

Comments
 (0)