Skip to content

Commit 4b30c41

Browse files
author
MarcoFalke
committed
Merge #18927: Pass bilingual_str argument to AbortNode()
5527be0 refactor: Add AbortError alias (Hennadii Stepanov) d924f2a Drop MSG_NOPREFIX flag (Hennadii Stepanov) 083daf7 Pass bilingual_str argument to AbortNode() (Hennadii Stepanov) d1cca12 refactor: Use bilingual_str::empty() (Hennadii Stepanov) Pull request description: This PR is a [followup](bitcoin/bitcoin#16218 (comment)) of #16224, and it adds `bilingual_str` type argument support to the `AbortNode()` functions. ACKs for top commit: MarcoFalke: ACK 5527be0 👟 Tree-SHA512: bf8b15b14912b1f672e6e588fffa1e6eb6f00b4b23d15d0ced7f18fbdf76919244427feb7217007fe29617049308e13def893a03a87358db819cca9692f59905
2 parents 0afbeb7 + 5527be0 commit 4b30c41

File tree

5 files changed

+28
-38
lines changed

5 files changed

+28
-38
lines changed

src/noui.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,20 @@ bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string&
2323
{
2424
bool fSecure = style & CClientUIInterface::SECURE;
2525
style &= ~CClientUIInterface::SECURE;
26-
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
27-
style &= ~CClientUIInterface::MSG_NOPREFIX;
2826

2927
std::string strCaption;
30-
if (prefix) {
31-
switch (style) {
32-
case CClientUIInterface::MSG_ERROR:
33-
strCaption = "Error: ";
34-
break;
35-
case CClientUIInterface::MSG_WARNING:
36-
strCaption = "Warning: ";
37-
break;
38-
case CClientUIInterface::MSG_INFORMATION:
39-
strCaption = "Information: ";
40-
break;
41-
default:
42-
strCaption = caption + ": "; // Use supplied caption (can be empty)
43-
}
28+
switch (style) {
29+
case CClientUIInterface::MSG_ERROR:
30+
strCaption = "Error: ";
31+
break;
32+
case CClientUIInterface::MSG_WARNING:
33+
strCaption = "Warning: ";
34+
break;
35+
case CClientUIInterface::MSG_INFORMATION:
36+
strCaption = "Information: ";
37+
break;
38+
default:
39+
strCaption = caption + ": "; // Use supplied caption (can be empty)
4440
}
4541

4642
if (!fSecure) {

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,21 +1069,18 @@ void BitcoinGUI::message(const QString& title, QString message, unsigned int sty
10691069
int nMBoxIcon = QMessageBox::Information;
10701070
int nNotifyIcon = Notificator::Information;
10711071

1072-
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
1073-
style &= ~CClientUIInterface::MSG_NOPREFIX;
1074-
10751072
QString msgType;
10761073
if (!title.isEmpty()) {
10771074
msgType = title;
10781075
} else {
10791076
switch (style) {
10801077
case CClientUIInterface::MSG_ERROR:
10811078
msgType = tr("Error");
1082-
if (prefix) message = tr("Error: %1").arg(message);
1079+
message = tr("Error: %1").arg(message);
10831080
break;
10841081
case CClientUIInterface::MSG_WARNING:
10851082
msgType = tr("Warning");
1086-
if (prefix) message = tr("Warning: %1").arg(message);
1083+
message = tr("Warning: %1").arg(message);
10871084
break;
10881085
case CClientUIInterface::MSG_INFORMATION:
10891086
msgType = tr("Information");

src/qt/walletcontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ void CreateWalletActivity::finish()
262262
{
263263
destroyProgressDialog();
264264

265-
if (!m_error_message.original.empty()) {
265+
if (!m_error_message.empty()) {
266266
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), QString::fromStdString(m_error_message.translated));
267267
} else if (!m_warning_message.empty()) {
268268
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));
@@ -303,7 +303,7 @@ void OpenWalletActivity::finish()
303303
{
304304
destroyProgressDialog();
305305

306-
if (!m_error_message.original.empty()) {
306+
if (!m_error_message.empty()) {
307307
QMessageBox::critical(m_parent_widget, tr("Open wallet failed"), QString::fromStdString(m_error_message.translated));
308308
} else if (!m_warning_message.empty()) {
309309
QMessageBox::warning(m_parent_widget, tr("Open wallet warning"), QString::fromStdString(Join(m_warning_message, Untranslated("\n")).translated));

src/ui_interface.h

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

70-
/** Do not prepend error/warning prefix */
71-
MSG_NOPREFIX = 0x20000000U,
72-
7370
/** Do not print contents of message to debug log */
7471
SECURE = 0x40000000U,
7572

src/validation.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,24 +1662,24 @@ bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex)
16621662
return true;
16631663
}
16641664

1665+
constexpr auto AbortError = InitError;
1666+
16651667
/** Abort with a message */
1666-
// TODO: AbortNode() should take bilingual_str userMessage parameter.
1667-
static bool AbortNode(const std::string& strMessage, const std::string& userMessage = "", unsigned int prefix = 0)
1668+
static bool AbortNode(const std::string& strMessage, bilingual_str user_message = bilingual_str())
16681669
{
16691670
SetMiscWarning(Untranslated(strMessage));
16701671
LogPrintf("*** %s\n", strMessage);
1671-
if (!userMessage.empty()) {
1672-
uiInterface.ThreadSafeMessageBox(Untranslated(userMessage), "", CClientUIInterface::MSG_ERROR | prefix);
1673-
} else {
1674-
uiInterface.ThreadSafeMessageBox(_("Error: A fatal internal error occurred, see debug.log for details"), "", CClientUIInterface::MSG_ERROR | CClientUIInterface::MSG_NOPREFIX);
1672+
if (user_message.empty()) {
1673+
user_message = _("A fatal internal error occurred, see debug.log for details");
16751674
}
1675+
AbortError(user_message);
16761676
StartShutdown();
16771677
return false;
16781678
}
16791679

1680-
static bool AbortNode(BlockValidationState& state, const std::string& strMessage, const std::string& userMessage = "", unsigned int prefix = 0)
1680+
static bool AbortNode(BlockValidationState& state, const std::string& strMessage, const bilingual_str& userMessage = bilingual_str())
16811681
{
1682-
AbortNode(strMessage, userMessage, prefix);
1682+
AbortNode(strMessage, userMessage);
16831683
return state.Error(strMessage);
16841684
}
16851685

@@ -2344,7 +2344,7 @@ bool CChainState::FlushStateToDisk(
23442344
if (fDoFullFlush || fPeriodicWrite) {
23452345
// Depend on nMinDiskSpace to ensure we can write block index
23462346
if (!CheckDiskSpace(GetBlocksDir())) {
2347-
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
2347+
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
23482348
}
23492349
{
23502350
LOG_TIME_MILLIS_WITH_CATEGORY("write block and undo data to disk", BCLog::BENCH);
@@ -2392,7 +2392,7 @@ bool CChainState::FlushStateToDisk(
23922392
// an overestimation, as most will delete an existing entry or
23932393
// overwrite one. Still, use a conservative safety factor of 2.
23942394
if (!CheckDiskSpace(GetDataDir(), 48 * 2 * 2 * CoinsTip().GetCacheSize())) {
2395-
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
2395+
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
23962396
}
23972397
// Flush the chainstate (which may refer to block index entries).
23982398
if (!CoinsTip().Flush())
@@ -3299,7 +3299,7 @@ static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, unsigned int n
32993299
bool out_of_space;
33003300
size_t bytes_allocated = BlockFileSeq().Allocate(pos, nAddSize, out_of_space);
33013301
if (out_of_space) {
3302-
return AbortNode("Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
3302+
return AbortNode("Disk space is too low!", _("Disk space is too low!"));
33033303
}
33043304
if (bytes_allocated != 0 && fPruneMode) {
33053305
fCheckForPruning = true;
@@ -3323,7 +3323,7 @@ static bool FindUndoPos(BlockValidationState &state, int nFile, FlatFilePos &pos
33233323
bool out_of_space;
33243324
size_t bytes_allocated = UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
33253325
if (out_of_space) {
3326-
return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!").translated, CClientUIInterface::MSG_NOPREFIX);
3326+
return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
33273327
}
33283328
if (bytes_allocated != 0 && fPruneMode) {
33293329
fCheckForPruning = true;

0 commit comments

Comments
 (0)