Skip to content

Conversation

@hebasto
Copy link
Member

@hebasto hebasto commented Apr 25, 2019

The "Error" prefix/title is set already in the next functions:

  • noui_ThreadSafeMessageBox()
    bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
  • ThreadSafeMessageBox()
    static bool ThreadSafeMessageBox(BitcoinGUI* gui, const std::string& message, const std::string& caption, unsigned int style)

Currently on master:
Screenshot from 2019-04-25 22-08-54

With this PR:
Screenshot from 2019-04-25 22-26-36

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK ad2b70aa26cecbcc42c305401855212de9b3c26c. Code change seems good, but I think ideally the line would appear as "Error: Disk space is low!" in both the GUI and in the log. As it stands currently, it seems this like this change makes the log message better but the GUI message a little worse.

@practicalswift
Copy link
Contributor

utACK ad2b70aa26cecbcc42c305401855212de9b3c26c

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 25, 2019

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@Sjors
Copy link
Member

Sjors commented Apr 27, 2019

utACK ad2b70a, that was annoying me too. @ryanofsky I don't think the UI dialog text needs a "Error: " prefix. The dialog title and giant red icon make it clear enough that this is an error.

@promag
Copy link
Contributor

promag commented Apr 28, 2019

On macos the message box title is missing, should fix that at least?
Screenshot 2019-04-28 at 23 34 14

@hebasto
Copy link
Member Author

hebasto commented Apr 29, 2019

@promag https://doc.qt.io/qt-5/qmessagebox.html#setWindowTitle

On macOS, the window title is ignored (as required by the macOS Guidelines).

I can see two possible ways:

  • platform-dependent QMessageBox text:
    • "Error: Message" on macOS
    • "Message" on other platforms
  • do not touch GUI code at all

Which one is more preferable?

@promag
Copy link
Contributor

promag commented Apr 29, 2019

I agree with @ryanofsky, having equal messages isn't that terrible, especially when it's about to quit.

@jonasschnelli
Copy link
Contributor

Thanks for working on this.
I agree with @ryanofsky that the message should be the same.

Maybe the wording should be more "final" since "low" is eventually something that is non-critical were "too low" would be understandable (together with red error sign).

@Sjors
Copy link
Member

Sjors commented Apr 29, 2019

Maybe add a comment in source to remind us of the macOS situation.

@maflcko
Copy link
Member

maflcko commented Apr 29, 2019

What about prepending the prefix based on the error type?

diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index abf9136eee..851bfe2b71 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -1022,9 +1022,9 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
     progressBar->setToolTip(tooltip);
 }
 
-void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
+void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret)
 {
-    QString strTitle = tr("Bitcoin"); // default title
+    QString strTitle{PACKAGE_NAME}; // default title
     // Default to information icon
     int nMBoxIcon = QMessageBox::Information;
     int nNotifyIcon = Notificator::Information;
@@ -1039,20 +1039,24 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
         switch (style) {
         case CClientUIInterface::MSG_ERROR:
             msgType = tr("Error");
+            message = tr("Error") + ": " + message;
             break;
         case CClientUIInterface::MSG_WARNING:
             msgType = tr("Warning");
+            message = tr("Warning") + ": " + message;
             break;
         case CClientUIInterface::MSG_INFORMATION:
             msgType = tr("Information");
+            message = tr("Information") + ": " + message;
             break;
         default:
             break;
         }
     }
-    // Append title to "Bitcoin - "
-    if (!msgType.isEmpty())
+    // Append type to title
+    if (!msgType.isEmpty()) {
         strTitle += " - " + msgType;
+    }
 
     // Check for error/warning icon
     if (style & CClientUIInterface::ICON_ERROR) {
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
index b58ccbb455..54a4b3903c 100644
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -219,7 +219,7 @@ public Q_SLOTS:
                             @see CClientUIInterface::MessageBoxFlags
        @param[in] ret       pointer to a bool that will be modified to whether Ok was clicked (modal only)
     */
-    void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
+    void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr);
 
 #ifdef ENABLE_WALLET
     void setCurrentWallet(WalletModel* wallet_model);

@ryanofsky
Copy link
Contributor

ryanofsky commented Apr 29, 2019

re: #15894 (comment)

message = tr("Error") + ": " + message;

Formatting could be part of the translation:

message = tr("Error: %s", message)

@hebasto hebasto changed the title trivial, qt: Remove duplicated "Error: " prefix Remove duplicated "Error: " prefix in logs Apr 29, 2019
@hebasto
Copy link
Member Author

hebasto commented Apr 30, 2019

Currently, Bitcoin Core code has the following features.

The ThreadSafeMessageBox() messages are rendered in two ways:

  • by noui_ThreadSafeMessageBox() using LogPrintf() and fprintf(stderr, ...) with
    adding translated type prefix ("Error" / "Warning" / "Information")
  • by BitcoinGUI::message() using QMessageBox with adding translated type suffix ("Error" / "Warning" / "Information") to the window title. Note: On macOS, the window title is ignored (as required by the macOS Guidelines)

The ThreadSafeMessageBox() is called by some functions:

  • AbortNode() and InitRPCAuthentication() pass translated messages with "Error: " prefix
  • FatalError() passes non translated messages with "Error: " prefix
  • InitError(); some passed messages are translated, some are not
  • InitWarning() passes translated messages
  • InitHTTPAllowList() passes non-translated messages
  • CCoinsViewErrorCatcher::GetCoin() pass translated message started with "Error"
  • CConnman::BindListenPort() via CConnman::Bind() passes:
    • non translated messages with "Error: " prefix
    • translated messages without any prefix
    • translated messages with "Error: " prefix
  • CConnman::Start() passes translated messages
  • AddTimeData() passes translated message

Unfortunately, I cannot see the simple way to refactor the code to achieve both uniformity and usability.

Any thoughts?

@ryanofsky
Copy link
Contributor

re: #15894 (comment) from hebasto

Unfortunately, I cannot see the simple way to refactor the code to achieve both uniformity and usability.

I think it'd make sense to just focus on implementing desired behavior this PR, and not do a broad refactoring at the same time. It sounds like the goal is just to get identical translated "Error: Disk space is low!" messages to show up in the log and dialogs. Refactoring is something that can come later, and usually refactoring changes are more reviewable if they don't change behavior.

I think the easiest way to keep the PR limited would be to define a new CClientUIInterface::MSG_NOPREFIX flag, and have AbortNode pass it to noui_ThreadSafeMessageBox. AbortNode could also pass strprintf(_("Error: %s"), userMessage) instead of userMessage, and you could keep the existing changes in this PR. Maybe a few other AbortNode calls might need to be updated, too.

As for a bigger refactoring, I think Marco's suggested change #15894 (comment) could be a good idea since it makes BitcoinGUI::message formatting more similar to noui_ThreadSafeMessageBox message formatting.

An alternative would go the opposite direction and make noui_ThreadSafeMessageBox more similar to BitcoinGUI::message, giving callers more control over formatting. If we wanted to do this, it might help to add some utility functions to util/error.h and util/error.cpp that callers could use:

std::string FormatError(const std::string& message)
{
    return strprintf(_("Error: %s"), message);
}

std::string FormatWarning(const std::string& message)
{
    return strprintf(_("Warning: %s"), message);
}

@maflcko
Copy link
Member

maflcko commented Apr 30, 2019

Logging translated messages to debug.log is a bug (it makes the log useless as universally understood debugging medium)

Steps to reproduce:

$ ./src/qt/bitcoin-qt -whitelist=asdf -lang=fr -printtoconsole

...
2019-04-30T13:11:46Z nBestHeight = 3045
2019-04-30T13:11:46Z torcontrol thread start
2019-04-30T13:11:46Z Erreur: Masque réseau invalide indiqué dans -whitelist : « asdf »

@hebasto
Copy link
Member Author

hebasto commented Apr 30, 2019

@MarcoFalke
Agree. There was a dedicated PR #15340.

@ryanofsky
Copy link
Contributor

ryanofsky commented Apr 30, 2019

Logging translated messages to debug.log is a bug (it makes the log useless as universally understood debugging medium)

Does this impact my suggestion above? It seems like currently we log both translated and untranslated messages, and after my suggestion we'd continue to do that. My suggestion is just about making prefixes in translated messages consistent.

More generally, I don't see any harm in logging translated messages next to untranslated messages. Seems fine if you want to drop translated messages, though.

@hebasto
Copy link
Member Author

hebasto commented Apr 30, 2019

Just a reminder:

Translation Strings Policy:

Do not translate internal errors, log messages, or messages that appear on the RPC interface. If an error is to be shown to the user, use a translatable generic message, then log the detailed message to the log. E.g., "A fatal internal error occurred, see debug.log for details". This helps troubleshooting; if the error is the same for everyone, the likelihood is increased that it can be found using a search engine.

@hebasto hebasto force-pushed the 20190425-duplicated-error-prefix branch from ad2b70a to 657db09 Compare April 30, 2019 19:00
@hebasto
Copy link
Member Author

hebasto commented Apr 30, 2019

The following comments have been addressed:

... I think ideally the line would appear as "Error: Disk space is low!" in both the GUI and in the log.

Maybe the wording should be more "final" since "low" is eventually something that is non-critical were "too low" would be understandable (together with red error sign).

Maybe add a comment in source to remind us of the macOS situation.

What about prepending the prefix based on the error type?

I think the easiest way to keep the PR limited would be to define a new CClientUIInterface::MSG_NOPREFIX flag, and have AbortNode pass it to noui_ThreadSafeMessageBox.

The result:
Screenshot from 2019-04-30 21-59-32

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 657db0932e3a9621935c5edc36ae269c80d6d9a4. To be sure, this is not the change I was suggesting. I would have preferred to just add the "Error:" prefix unconditionally in AbortNode() so it wouldn't need to have a new argument added. I also would have preferred not to change BitcoinGUI::message so the scope of this PR would be limited to AbortNode calls and not affect every other error dialog. But either way this is ok.

@hebasto hebasto force-pushed the 20190425-duplicated-error-prefix branch from 657db09 to 4dc36fa Compare April 30, 2019 19:57
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 4dc36faf4b9b419ae1eec837e36d0bb60a6255b3. Only change since last review is capitalization.

@hebasto hebasto force-pushed the 20190425-duplicated-error-prefix branch from 4dc36fa to f724f31 Compare June 19, 2019 16:23
@hebasto
Copy link
Member Author

hebasto commented Jun 19, 2019

Rebased.

@laanwj
Copy link
Member

laanwj commented Jun 25, 2019

concept and code-review ACK f724f31

@laanwj laanwj merged commit f724f31 into bitcoin:master Jun 25, 2019
laanwj added a commit that referenced this pull request Jun 25, 2019
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
@hebasto hebasto deleted the 20190425-duplicated-error-prefix branch June 25, 2019 14:32
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions

@hebasto
Copy link
Member Author

hebasto commented Jun 25, 2019

@MarcoFalke Thank you for your review. I could see my code from another point of view.

maflcko pushed a commit that referenced this pull request May 8, 2020
18bd83b util: Cleanup translation.h (Hennadii Stepanov)
e95e658 doc: Do not translate technical or extremely rare errors (Hennadii Stepanov)
7e923d4 Make InitError bilingual (Hennadii Stepanov)
917ca93 Make ThreadSafe{MessageBox|Question} bilingual (Hennadii Stepanov)
23b9fa2 gui: Add detailed text to BitcoinGUI::message (Hennadii Stepanov)

Pull request description:

  This is an alternative to #15340 (it works with the `Chain` interface; see: #15340 (comment)).
  Refs:
  - #16218 (partial fix)
  - #15894 (comment)

  This PR:
  - makes GUI error messages bilingual: user's native language + untranslated (i.e. English)
  - insures that only untranslated messages are written to the debug log file and to `stderr` (that is not the case on master).

  If a translated string is unavailable only an English string appears to a user.

  Here are some **examples** (updated):

  ![Screenshot from 2020-04-24 17-08-37](https://user-images.githubusercontent.com/32963518/80222043-e2458780-864e-11ea-83fc-197b7121dba5.png)

  ![Screenshot from 2020-04-24 17-12-17](https://user-images.githubusercontent.com/32963518/80222051-e5407800-864e-11ea-92f7-dfef1144becd.png)

  * `qt5ct: using qt5ct plugin` message is my local environment specific; please ignore it.

  ---

  Note for reviewers: `InitWarning()` is out of this PR scope.

ACKs for top commit:
  Sjors:
    re-tACK 18bd83b
  MarcoFalke:
    ACK 18bd83b 🐦

Tree-SHA512: 3cc8ec44f84403e54b57d11714c86b0855ed90eb794b5472e432005073354b9e3f7b4e8e7bf347a4c21be47299dbc7170f2d0c4b80e308205ff09596e55a4f96
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 12, 2020
18bd83b util: Cleanup translation.h (Hennadii Stepanov)
e95e658 doc: Do not translate technical or extremely rare errors (Hennadii Stepanov)
7e923d4 Make InitError bilingual (Hennadii Stepanov)
917ca93 Make ThreadSafe{MessageBox|Question} bilingual (Hennadii Stepanov)
23b9fa2 gui: Add detailed text to BitcoinGUI::message (Hennadii Stepanov)

Pull request description:

  This is an alternative to bitcoin#15340 (it works with the `Chain` interface; see: bitcoin#15340 (comment)).
  Refs:
  - bitcoin#16218 (partial fix)
  - bitcoin#15894 (comment)

  This PR:
  - makes GUI error messages bilingual: user's native language + untranslated (i.e. English)
  - insures that only untranslated messages are written to the debug log file and to `stderr` (that is not the case on master).

  If a translated string is unavailable only an English string appears to a user.

  Here are some **examples** (updated):

  ![Screenshot from 2020-04-24 17-08-37](https://user-images.githubusercontent.com/32963518/80222043-e2458780-864e-11ea-83fc-197b7121dba5.png)

  ![Screenshot from 2020-04-24 17-12-17](https://user-images.githubusercontent.com/32963518/80222051-e5407800-864e-11ea-92f7-dfef1144becd.png)

  * `qt5ct: using qt5ct plugin` message is my local environment specific; please ignore it.

  ---

  Note for reviewers: `InitWarning()` is out of this PR scope.

ACKs for top commit:
  Sjors:
    re-tACK 18bd83b
  MarcoFalke:
    ACK 18bd83b 🐦

Tree-SHA512: 3cc8ec44f84403e54b57d11714c86b0855ed90eb794b5472e432005073354b9e3f7b4e8e7bf347a4c21be47299dbc7170f2d0c4b80e308205ff09596e55a4f96
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 5, 2020
Summary:
bitcoin/bitcoin@f0641f2

---

Partial backport of Core [[bitcoin/bitcoin#15894 | PR15894]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7124
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 5, 2020
Summary:
It forces do not prepend error/warning prefix.

bitcoin/bitcoin@96fd4ee

---

Depends on D7124

Partial backport of Core [[bitcoin/bitcoin#15894 | PR15894]]

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7125
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Aug 5, 2020
Summary:
bitcoin/bitcoin@f724f31

---

Depends on D7125

Concludes backport of Core [[bitcoin/bitcoin#15894 | PR15894]]

Test Plan:
  ninja check check-functional

Reviewers: #bitcoin_abc, jasonbcox

Reviewed By: #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7126
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Nov 18, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants