Remove duplicated “Error: " prefix in logs #15894

pull hebasto wants to merge 3 commits into bitcoin:master from hebasto:20190425-duplicated-error-prefix changing 5 files +52 −41
  1. hebasto commented at 7:44 pm on April 25, 2019: member

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

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

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

  2. DrahtBot added the label Validation on Apr 25, 2019
  3. ryanofsky approved
  4. ryanofsky commented at 9:17 pm on April 25, 2019: member
    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.
  5. practicalswift commented at 9:33 pm on April 25, 2019: contributor
    utACK ad2b70aa26cecbcc42c305401855212de9b3c26c
  6. DrahtBot commented at 10:14 pm on April 25, 2019: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16224 (gui: Bilingual GUI error messages by hebasto)
    • #15921 (Tidy up ValidationState interface by jnewbery)
    • #13674 (Qt: Fix for bitcoin-qt becoming unresponsive during shutdown (issue #13217) by LeandroRocha84)

    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.

  7. Sjors commented at 6:55 pm on April 27, 2019: member
    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.
  8. promag commented at 10:37 pm on April 28, 2019: member
    On macos the message box title is missing, should fix that at least?
  9. hebasto commented at 6:35 am on April 29, 2019: member

    @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?

  10. promag commented at 6:41 am on April 29, 2019: member
    I agree with @ryanofsky, having equal messages isn’t that terrible, especially when it’s about to quit.
  11. jonasschnelli commented at 6:52 am on April 29, 2019: 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).

  12. Sjors commented at 8:57 am on April 29, 2019: member
    Maybe add a comment in source to remind us of the macOS situation.
  13. MarcoFalke commented at 12:21 pm on April 29, 2019: member

    What about prepending the prefix based on the error type?

     0diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
     1index abf9136eee..851bfe2b71 100644
     2--- a/src/qt/bitcoingui.cpp
     3+++ b/src/qt/bitcoingui.cpp
     4@@ -1022,9 +1022,9 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
     5     progressBar->setToolTip(tooltip);
     6 }
     7 
     8-void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
     9+void BitcoinGUI::message(const QString& title, QString message, unsigned int style, bool* ret)
    10 {
    11-    QString strTitle = tr("Bitcoin"); // default title
    12+    QString strTitle{PACKAGE_NAME}; // default title
    13     // Default to information icon
    14     int nMBoxIcon = QMessageBox::Information;
    15     int nNotifyIcon = Notificator::Information;
    16@@ -1039,20 +1039,24 @@ void BitcoinGUI::message(const QString &title, const QString &message, unsigned
    17         switch (style) {
    18         case CClientUIInterface::MSG_ERROR:
    19             msgType = tr("Error");
    20+            message = tr("Error") + ": " + message;
    21             break;
    22         case CClientUIInterface::MSG_WARNING:
    23             msgType = tr("Warning");
    24+            message = tr("Warning") + ": " + message;
    25             break;
    26         case CClientUIInterface::MSG_INFORMATION:
    27             msgType = tr("Information");
    28+            message = tr("Information") + ": " + message;
    29             break;
    30         default:
    31             break;
    32         }
    33     }
    34-    // Append title to "Bitcoin - "
    35-    if (!msgType.isEmpty())
    36+    // Append type to title
    37+    if (!msgType.isEmpty()) {
    38         strTitle += " - " + msgType;
    39+    }
    40 
    41     // Check for error/warning icon
    42     if (style & CClientUIInterface::ICON_ERROR) {
    43diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
    44index b58ccbb455..54a4b3903c 100644
    45--- a/src/qt/bitcoingui.h
    46+++ b/src/qt/bitcoingui.h
    47@@ -219,7 +219,7 @@ public Q_SLOTS: [@see](/bitcoin-bitcoin/contributor/see/) CClientUIInterface::MessageBoxFlags [@param](/bitcoin-bitcoin/contributor/param/)[in] ret       pointer to a bool that will be modified to whether Ok was clicked (modal only)
    48     */
    49-    void message(const QString &title, const QString &message, unsigned int style, bool *ret = nullptr);
    50+    void message(const QString& title, QString message, unsigned int style, bool* ret = nullptr);
    51 
    52 #ifdef ENABLE_WALLET
    53     void setCurrentWallet(WalletModel* wallet_model);
    
  14. ryanofsky commented at 3:25 pm on April 29, 2019: member

    re: #15894 (comment)

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

    Formatting could be part of the translation:

    0message = tr("Error: %s", message)
    
  15. hebasto renamed this:
    trivial, qt: Remove duplicated "Error: " prefix
    Remove duplicated "Error: " prefix in logs
    on Apr 29, 2019
  16. hebasto commented at 11:18 am on April 30, 2019: member

    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?

  17. ryanofsky commented at 12:35 pm on April 30, 2019: member

    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:

    0std::string FormatError(const std::string& message)
    1{
    2    return strprintf(_("Error: %s"), message);
    3}
    4
    5std::string FormatWarning(const std::string& message)
    6{
    7    return strprintf(_("Warning: %s"), message);
    8}
    
  18. MarcoFalke commented at 1:14 pm on April 30, 2019: member

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

    Steps to reproduce:

    0$ ./src/qt/bitcoin-qt -whitelist=asdf -lang=fr -printtoconsole
    1
    2...
    32019-04-30T13:11:46Z nBestHeight = 3045
    42019-04-30T13:11:46Z torcontrol thread start
    52019-04-30T13:11:46Z Erreur: Masque réseau invalide indiqué dans -whitelist : « asdf »
    
  19. hebasto commented at 1:17 pm on April 30, 2019: member
    @MarcoFalke Agree. There was a dedicated PR #15340.
  20. ryanofsky commented at 1:50 pm on April 30, 2019: member

    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.

  21. hebasto commented at 2:01 pm on April 30, 2019: member

    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.

  22. hebasto force-pushed on Apr 30, 2019
  23. hebasto commented at 7:09 pm on April 30, 2019: member

    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

  24. in src/qt/bitcoingui.cpp:1041 in 6a21f03d7d outdated
    1039-    else {
    1040+    } else {
    1041         switch (style) {
    1042         case CClientUIInterface::MSG_ERROR:
    1043-            msgType = tr("Error");
    1044+            msgType = tr("ERROR");
    


    ryanofsky commented at 7:21 pm on April 30, 2019:
    Why this is changing capitalization? All caps seems ugly.

    hebasto commented at 7:57 pm on April 30, 2019:
    Fixed.
  25. in src/qt/bitcoingui.cpp:1042 in 6a21f03d7d outdated
    1040+    } else {
    1041         switch (style) {
    1042         case CClientUIInterface::MSG_ERROR:
    1043-            msgType = tr("Error");
    1044+            msgType = tr("ERROR");
    1045+            message = tr("ERROR: %1").arg(message);
    


    ryanofsky commented at 7:32 pm on April 30, 2019:
    Is there a reason this is adding an “ERROR: " prefix for errors generically but using an “Error: " prefix for the disk space error? Why not be consistent?

    hebasto commented at 7:58 pm on April 30, 2019:
    Fixed.
  26. ryanofsky approved
  27. ryanofsky commented at 7:40 pm on April 30, 2019: member
    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.
  28. hebasto force-pushed on Apr 30, 2019
  29. ryanofsky approved
  30. ryanofsky commented at 8:14 pm on April 30, 2019: member
    utACK 4dc36faf4b9b419ae1eec837e36d0bb60a6255b3. Only change since last review is capitalization.
  31. DrahtBot added the label Needs rebase on Jun 17, 2019
  32. DrahtBot removed the label Needs rebase on Jun 17, 2019
  33. DrahtBot added the label Needs rebase on Jun 18, 2019
  34. Prepend the error/warning prefix for GUI messages f0641f274f
  35. Add MSG_NOPREFIX flag for user messages
    It forces do not prepend error/warning prefix.
    96fd4ee02f
  36. Make AbortNode() aware of MSG_NOPREFIX flag f724f31401
  37. hebasto force-pushed on Jun 19, 2019
  38. hebasto commented at 4:23 pm on June 19, 2019: member
    Rebased.
  39. DrahtBot removed the label Needs rebase on Jun 19, 2019
  40. laanwj commented at 11:32 am on June 25, 2019: member
    concept and code-review ACK f724f31401b963c75bd64f5e2c5b9d9561a9a9dd
  41. laanwj merged this on Jun 25, 2019
  42. laanwj closed this on Jun 25, 2019

  43. laanwj referenced this in commit 332c6134bb on Jun 25, 2019
  44. in src/qt/bitcoingui.cpp:1044 in f724f31401
    1037@@ -1038,49 +1038,51 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
    1038     progressBar->setToolTip(tooltip);
    1039 }
    1040 
    1041-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)
    1043 {
    1044-    QString strTitle = tr("Bitcoin"); // default title
    1045+    // Default title. On macOS, the window title is ignored (as required by the macOS Guidelines).
    1046+    QString strTitle{PACKAGE_NAME};
    


    MarcoFalke commented at 2:24 pm on June 25, 2019:
    Why is this no longer translated, like the other PACKAGE_NAMEs?

    hebasto commented at 6:15 pm on June 25, 2019:

    I’m agree that in the src/qt/ directory the translated PACKAGE_NAME is always used. How should I fix it when this PR has been merged already? A new PR?

    Why is this no longer translated..?

    The PACKAGE_NAME is a brand/product name which should not be translated, in my strong opinion. I’ve read rebranding discussion (#3203, #3400, #3408, …). Could you point me to a similar discussion regarding translation of the PACKAGE_NAME?

    Also, please note the next lines of code

    0    <message>
    1        <source>Bitcoin Core</source>
    2        <translation>Bitcoin Core</translation>
    3    </message>
    

    through almost(?) all files in the src/qt/locale/ directory.

    Maybe some national traditions force to translate foreign brand names? I don’t know about such traditions.


    MarcoFalke commented at 8:12 pm on June 25, 2019:
    Yeah, there have been a lot of discussions in the past, also on IRC. We should at least be self-consistent.

    hebasto commented at 8:30 pm on June 25, 2019:

    We should at least be self-consistent.

    Right.


    hebasto commented at 5:57 am on July 9, 2019:
    As #16291 is merged I’m going to resolve this conversation.
  45. in src/qt/bitcoingui.cpp:1059 in f724f31401
    1060-    else {
    1061+    } else {
    1062         switch (style) {
    1063         case CClientUIInterface::MSG_ERROR:
    1064             msgType = tr("Error");
    1065+            if (prefix) message = tr("Error: %1").arg(message);
    


    MarcoFalke commented at 2:26 pm on June 25, 2019:
    Why can’t this use the existing translation of tr("Error")? Seems overkill to burden the translator with a format string.

    hebasto commented at 6:34 pm on June 25, 2019:
    Please, see the #15894 (comment) by @ryanofsky.

    MarcoFalke commented at 6:44 pm on June 25, 2019:
    That explains that it can be done, not why.

    hebasto commented at 7:20 pm on June 25, 2019:
    Maybe this could explain that? If not, would you mind providing the Bitcoin Core team’s best practices for such cases?
  46. in src/validation.cpp:2928 in f724f31401
    2924@@ -2923,7 +2925,7 @@ static bool FindUndoPos(CValidationState &state, int nFile, FlatFilePos &pos, un
    2925     bool out_of_space;
    2926     size_t bytes_allocated = UndoFileSeq().Allocate(pos, nAddSize, out_of_space);
    2927     if (out_of_space) {
    2928-        return AbortNode(state, "Disk space is low!", _("Error: Disk space is low!"));
    2929+        return AbortNode(state, "Disk space is too low!", _("Error: Disk space is too low!"), CClientUIInterface::MSG_NOPREFIX);
    


    MarcoFalke commented at 2:32 pm on June 25, 2019:
    Since you are changing the translation here anyway, might as well remove the prefix and not set the flag?

    hebasto commented at 6:40 pm on June 25, 2019:

    Please see:


    MarcoFalke commented at 6:46 pm on June 25, 2019:

    Yeah, I’d say it is shorter to write

    0return AbortNode(state, "Disk space is too low!", _("Disk space is too low!"));
    

    which should do the same?


    hebasto commented at 7:58 pm on June 25, 2019:

    which should do the same?

    Not quite. The difference is whether {“Error: “|“Warning: “:} prefix is translated or not in the debug.log and stderr.


    MarcoFalke commented at 8:43 pm on June 25, 2019:

    Right. I guess it shouldn’t, but at the current state of this pull request, it is translated.

    I presume you are fixing this in #16224 (or similar)?


    hebasto commented at 8:52 pm on June 25, 2019:
    Yes. I think it was my fault to touch translations in this PR ((
  47. hebasto deleted the branch on Jun 25, 2019
  48. in src/validation.cpp:1392 in f724f31401
    1393 
    1394-static bool AbortNode(CValidationState& state, const std::string& strMessage, const std::string& userMessage="")
    1395+static bool AbortNode(CValidationState& state, const std::string& strMessage, const std::string& userMessage = "", unsigned int prefix = 0)
    1396 {
    1397-    AbortNode(strMessage, userMessage);
    1398+    AbortNode(strMessage, userMessage, prefix);
    


    MarcoFalke commented at 2:32 pm on June 25, 2019:
    The param should be named msg_prefix or something more specific, no?

    hebasto commented at 6:20 pm on June 25, 2019:
    Agree. How should I fix it when this PR has been merged already? A new PR?

    Sjors commented at 0:38 am on June 26, 2019:
    A new PR is the best approach.
  49. in src/validation.cpp:1381 in f724f31401
    1380     SetMiscWarning(strMessage);
    1381     LogPrintf("*** %s\n", strMessage);
    1382-    uiInterface.ThreadSafeMessageBox(
    1383-        userMessage.empty() ? _("Error: A fatal internal error occurred, see debug.log for details") : userMessage,
    1384-        "", CClientUIInterface::MSG_ERROR);
    1385+    if (!userMessage.empty()) {
    


    MarcoFalke commented at 2:33 pm on June 25, 2019:
    style-nit: Generally it is preferred to not invert the condition if there is an else clause anyway.

    hebasto commented at 6:19 pm on June 25, 2019:
    Agree. How should I fix it when this PR has been merged already? A new PR?
  50. in src/noui.cpp:28 in f724f31401
    36-    default:
    37-        strCaption += caption; // Use supplied caption (can be empty)
    38+    if (prefix) {
    39+        switch (style) {
    40+        case CClientUIInterface::MSG_ERROR:
    41+            strCaption = "Error: ";
    


    MarcoFalke commented at 2:35 pm on June 25, 2019:
    Why is this no longer translated?

    hebasto commented at 6:24 pm on June 25, 2019:
    Because it will be printed to debug.log and/or stderr (also, see #15894 (comment)).
  51. MarcoFalke commented at 2:37 pm on June 25, 2019: member
    Some questions
  52. hebasto commented at 8:05 pm on June 25, 2019: member
    @MarcoFalke Thank you for your review. I could see my code from another point of view.
  53. MarcoFalke referenced this in commit 5b24f6084e on May 8, 2020
  54. sidhujag referenced this in commit fc9f727a08 on May 12, 2020
  55. jasonbcox referenced this in commit 564f890228 on Aug 5, 2020
  56. deadalnix referenced this in commit 53fee36fe9 on Aug 5, 2020
  57. deadalnix referenced this in commit 77d79c034e on Aug 5, 2020
  58. Munkybooty referenced this in commit 2efcb967d0 on Nov 2, 2021
  59. Munkybooty referenced this in commit bb5527b4d4 on Nov 2, 2021
  60. Munkybooty referenced this in commit 599d89c585 on Nov 4, 2021
  61. Munkybooty referenced this in commit e9c21d2288 on Nov 16, 2021
  62. Munkybooty referenced this in commit 93f168eee3 on Nov 18, 2021
  63. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me