aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2023-02-24 13:44:07 -0500
committerRyan Ofsky <ryan@ofsky.org>2023-02-28 12:04:47 -0500
commitd172b5c6718b69200c8ad211fe709860081bd692 (patch)
treeac3cbcb7debb57b9fa06233ca0fc3ba124b5d6d6 /src
parent3db2874bd71d2391747b7385cabcbfef67218c4c (diff)
downloadbitcoin-d172b5c6718b69200c8ad211fe709860081bd692.tar.xz
Add InitError(error, details) overload
This is only used in the current PR to avoid ugly `strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)` boilerplate in init code. But in the future the function could be extended and more widely used to include more details in GUI error messages or display them in a more readable way, see code comment.
Diffstat (limited to 'src')
-rw-r--r--src/index/base.cpp2
-rw-r--r--src/node/interface_ui.cpp13
-rw-r--r--src/node/interface_ui.h2
-rw-r--r--src/shutdown.cpp2
4 files changed, 16 insertions, 3 deletions
diff --git a/src/index/base.cpp b/src/index/base.cpp
index 6f2ce2efe4..7c570d4534 100644
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -35,7 +35,7 @@ static void FatalError(const char* fmt, const Args&... args)
std::string strMessage = tfm::format(fmt, args...);
SetMiscWarning(Untranslated(strMessage));
LogPrintf("*** %s\n", strMessage);
- AbortError(_("A fatal internal error occurred, see debug.log for details"));
+ InitError(_("A fatal internal error occurred, see debug.log for details"));
StartShutdown();
}
diff --git a/src/node/interface_ui.cpp b/src/node/interface_ui.cpp
index 08d1e03541..9dd1e7d9cf 100644
--- a/src/node/interface_ui.cpp
+++ b/src/node/interface_ui.cpp
@@ -4,6 +4,7 @@
#include <node/interface_ui.h>
+#include <util/string.h>
#include <util/translation.h>
#include <boost/signals2/optional_last_value.hpp>
@@ -62,6 +63,18 @@ bool InitError(const bilingual_str& str)
return false;
}
+bool InitError(const bilingual_str& str, const std::vector<std::string>& details)
+{
+ // For now just flatten the list of error details into a string to pass to
+ // the base InitError overload. In the future, if more init code provides
+ // error details, the details could be passed separately from the main
+ // message for rich display in the GUI. But currently the only init
+ // functions which provide error details are ones that run during early init
+ // before the GUI uiInterface is registered, so there's no point passing
+ // main messages and details separately to uiInterface yet.
+ return InitError(details.empty() ? str : strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)));
+}
+
void InitWarning(const bilingual_str& str)
{
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
diff --git a/src/node/interface_ui.h b/src/node/interface_ui.h
index 9f6503b4a1..22c241cb78 100644
--- a/src/node/interface_ui.h
+++ b/src/node/interface_ui.h
@@ -116,7 +116,7 @@ void InitWarning(const bilingual_str& str);
/** Show error message **/
bool InitError(const bilingual_str& str);
-constexpr auto AbortError = InitError;
+bool InitError(const bilingual_str& str, const std::vector<std::string>& details);
extern CClientUIInterface uiInterface;
diff --git a/src/shutdown.cpp b/src/shutdown.cpp
index 57d6d2325d..2fffc0663c 100644
--- a/src/shutdown.cpp
+++ b/src/shutdown.cpp
@@ -27,7 +27,7 @@ bool AbortNode(const std::string& strMessage, bilingual_str user_message)
if (user_message.empty()) {
user_message = _("A fatal internal error occurred, see debug.log for details");
}
- AbortError(user_message);
+ InitError(user_message);
StartShutdown();
return false;
}