gui: Do not translate InitWarning messages in debug.log #18922

pull hebasto wants to merge 4 commits into bitcoin:master from hebasto:200509-initwarn changing 10 files +38 −29
  1. hebasto commented at 12:43 pm on May 9, 2020: member

    This PR forces the bitcoin-qt to write InitWarning() messages to the debug.log file in untranslated form, i.e., in English.

    On master (376294cde6b1588cb17055d8fde567eaf5848c3c):

    0$ ./src/qt/bitcoin-qt -lang=nl -debug=vladidation -printtoconsole | grep 'vladi'
    1Warning: Niet-ondersteunde logcategorie -debug=vladidation.
    22020-05-09T12:39:59Z Warning: Niet-ondersteunde logcategorie -debug=vladidation.
    32020-05-09T12:40:02Z Command-line arg: debug="vladidation"
    

    With this PR:

    0$ ./src/qt/bitcoin-qt -lang=nl -debug=vladidation -printtoconsole | grep 'vladi'
    1Warning: Unsupported logging category -debug=vladidation.
    22020-05-09T12:42:04Z Warning: Unsupported logging category -debug=vladidation.
    32020-05-09T12:42:35Z Command-line arg: debug="vladidation"
    

    Screenshot from 2020-05-09 15-42-31

    Related to #16218.

  2. in src/wallet/load.cpp:59 in 4e789b9459 outdated
    55@@ -56,7 +56,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
    56         bilingual_str error_string;
    57         std::vector<bilingual_str> warnings;
    58         bool verify_success = CWallet::Verify(chain, location, salvage_wallet, error_string, warnings);
    59-        if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", OpTranslated));
    60+        if (!warnings.empty()) chain.initWarning(Join(warnings, "\n", [](const bilingual_str& i) { return i; }));
    


    MarcoFalke commented at 1:25 pm on May 9, 2020:
    0        if (!warnings.empty()) chain.initWarning(Join(warnings, Untranslated("\n"));
    

    hebasto commented at 4:01 pm on May 9, 2020:
  3. in src/util/translation.h:27 in 4e789b9459 outdated
    22+        original += rhs.original;
    23+        translated += rhs.translated;
    24+        return *this;
    25+    }
    26+
    27+    bilingual_str& operator+=(const std::string& chars)
    


    MarcoFalke commented at 1:27 pm on May 9, 2020:
    I think it would be safer to not allow this and force the caller to go through Untranslated

    hebasto commented at 4:01 pm on May 9, 2020:
  4. in src/util/string.h:34 in 4e789b9459 outdated
    30@@ -31,9 +31,10 @@ NODISCARD inline std::string TrimString(const std::string& str, const std::strin
    31  * @param unary_op   Apply this operator to each item in the list
    32  */
    33 template <typename T, typename UnaryOp>
    34-std::string Join(const std::vector<T>& list, const std::string& separator, UnaryOp unary_op)
    35+auto Join(const std::vector<T>& list, const std::string& separator, UnaryOp unary_op)
    


    MarcoFalke commented at 1:31 pm on May 9, 2020:
    0auto Join(const std::vector<T>& list, const U& separator, UnaryOp unary_op)
    

    I think this requirement can be lifted (here and below)


    hebasto commented at 4:02 pm on May 9, 2020:
  5. MarcoFalke commented at 1:33 pm on May 9, 2020: member
    Didn’t know that auto return type is possible in C++11, but it seems to compile so why not :man_shrugging:
  6. util: Enhance bilingual_str fe05dd0611
  7. DrahtBot added the label GUI on May 9, 2020
  8. DrahtBot added the label Utils/log/libs on May 9, 2020
  9. DrahtBot added the label Wallet on May 9, 2020
  10. hebasto force-pushed on May 9, 2020
  11. hebasto commented at 4:00 pm on May 9, 2020: member

    Updated 4e789b9459ea3a5724cb30cccdaeb0d801f56e15 -> 6249e64acdcd865c44c74d311a079094f866fb75 (pr18922.01 -> pr18922.02, diff):

    • reworked following @MarcoFalke’s ideas and suggestions
  12. DrahtBot commented at 5:04 pm on May 9, 2020: 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:

    • #18927 (Pass bilingual_str argument to AbortNode() by hebasto)
    • #18918 (wallet: Move salvagewallet into wallettool by achow101)

    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.

  13. in src/wallet/rpcwallet.cpp:2740 in 6a4e883cdf outdated
    2736@@ -2737,7 +2737,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
    2737 
    2738     UniValue obj(UniValue::VOBJ);
    2739     obj.pushKV("name", wallet->GetName());
    2740-    obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
    2741+    obj.pushKV("warning", Join(warnings, std::string("\n"), OpOriginal));
    


    MarcoFalke commented at 5:12 pm on May 9, 2020:

    Please keep the explicit overload for std::string, if you want you can extend it with a comment why it exists.

    Also, I like the idea of deriving the return type from the unary operator

     0diff --git a/src/util/string.h b/src/util/string.h
     1index 81d4c186e5..e7651c3e7d 100644
     2--- a/src/util/string.h
     3+++ b/src/util/string.h
     4@@ -31,9 +31,10 @@ NODISCARD inline std::string TrimString(const std::string& str, const std::strin
     5  * [@param](/bitcoin-bitcoin/contributor/param/) unary_op   Apply this operator to each item in the list
     6  */
     7 template <typename T, typename BaseType, typename UnaryOp>
     8-BaseType Join(const std::vector<T>& list, const BaseType& separator, UnaryOp unary_op)
     9+auto Join(const std::vector<T>& list, const BaseType& separator, UnaryOp unary_op)
    10+    -> decltype(unary_op(list.at(0)))
    11 {
    12-    BaseType ret;
    13+    decltype(unary_op(list.at(0))) ret;
    14     for (size_t i = 0; i < list.size(); ++i) {
    15         if (i > 0) ret += separator;
    16         ret += unary_op(list.at(i));
    17@@ -47,6 +48,12 @@ T Join(const std::vector<T>& list, const T& separator)
    18     return Join(list, separator, [](const T& i) { return i; });
    19 }
    20 
    21+inline std::string Join(const std::vector<std::string>& list, const std::string& separator)
    22+{
    23+    // explicit overload needed for c_str, which would otherwise cause a substitution failure in the template above
    24+    return Join<std::string>(list, separator);
    25+}
    26+
    27 /**
    28  * Check if a string does not contain any embedded NUL (\0) characters
    29  */
    

    hebasto commented at 5:01 am on May 10, 2020:
  14. hebasto force-pushed on May 10, 2020
  15. hebasto commented at 4:58 am on May 10, 2020: member

    Updated 6249e64acdcd865c44c74d311a079094f866fb75 -> 3ddfa414787e017d9760b2ac55517986673a4b1c (pr18922.02 -> pr18922.03, diff):

    Please keep the explicit overload for std::string, if you want you can extend it with a comment why it exists.

    Also, I like the idea of deriving the return type from the unary operator

  16. elichai commented at 8:06 am on May 10, 2020: contributor

    Didn’t know that auto return type is possible in C++11, but it seems to compile so why not man_shrugging

    That’s interesting, I thought so too. But apparently IIUC C++11 supports auto return type, but requires you to put a trailing return type (-> return_type) from C++14 you can also skip that and the return type will be deduced.

  17. in src/rpc/util.cpp:754 in 3ddfa41478 outdated
    750@@ -751,7 +751,7 @@ std::string RPCArg::ToString(const bool oneline) const
    751     }
    752     case Type::OBJ:
    753     case Type::OBJ_USER_KEYS: {
    754-        const std::string res = Join(m_inner, ",", [&](const RPCArg& i) { return i.ToStringObj(oneline); });
    755+        const std::string res = Join(m_inner, std::string(","), [&](const RPCArg& i) { return i.ToStringObj(oneline); });
    


    MarcoFalke commented at 1:16 pm on May 10, 2020:

    Why are all these unrelated changes needed. This diff compiles fine for me on top:

     0diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
     1index 597da6e7fb..860fa198d5 100644
     2--- a/src/rpc/util.cpp
     3+++ b/src/rpc/util.cpp
     4@@ -751,7 +751,7 @@ std::string RPCArg::ToString(const bool oneline) const
     5     }
     6     case Type::OBJ:
     7     case Type::OBJ_USER_KEYS: {
     8-        const std::string res = Join(m_inner, std::string(","), [&](const RPCArg& i) { return i.ToStringObj(oneline); });
     9+        const std::string res = Join(m_inner, ",", [&](const RPCArg& i) { return i.ToStringObj(oneline); });
    10         if (m_type == Type::OBJ) {
    11             return "{" + res + "}";
    12         } else {
    13diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
    14index f71e7efa2b..45b7fd4932 100644
    15--- a/src/test/util_tests.cpp
    16+++ b/src/test/util_tests.cpp
    17@@ -141,15 +141,15 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
    18 BOOST_AUTO_TEST_CASE(util_Join)
    19 {
    20     // Normal version
    21-    BOOST_CHECK_EQUAL(Join({}, std::string(", ")), "");
    22-    BOOST_CHECK_EQUAL(Join({"foo"}, std::string(", ")), "foo");
    23-    BOOST_CHECK_EQUAL(Join({"foo", "bar"}, std::string(", ")), "foo, bar");
    24+    BOOST_CHECK_EQUAL(Join({}, ", "), "");
    25+    BOOST_CHECK_EQUAL(Join({"foo"}, ", "), "foo");
    26+    BOOST_CHECK_EQUAL(Join({"foo", "bar"}, ", "), "foo, bar");
    27 
    28     // Version with unary operator
    29     const auto op_upper = [](const std::string& s) { return ToUpper(s); };
    30-    BOOST_CHECK_EQUAL(Join<std::string>({}, std::string(", "), op_upper), "");
    31-    BOOST_CHECK_EQUAL(Join<std::string>({"foo"}, std::string(", "), op_upper), "FOO");
    32-    BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, std::string(", "), op_upper), "FOO, BAR");
    33+    BOOST_CHECK_EQUAL(Join<std::string>({}, ", ", op_upper), "");
    34+    BOOST_CHECK_EQUAL(Join<std::string>({"foo"}, ", ", op_upper), "FOO");
    35+    BOOST_CHECK_EQUAL(Join<std::string>({"foo", "bar"}, ", ", op_upper), "FOO, BAR");
    36 }
    37 
    38 BOOST_AUTO_TEST_CASE(util_FormatParseISO8601DateTime)
    39diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
    40index 0534befd3d..dda00f1fe7 100644
    41--- a/src/wallet/rpcwallet.cpp
    42+++ b/src/wallet/rpcwallet.cpp
    43@@ -2597,7 +2597,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
    44 
    45     UniValue obj(UniValue::VOBJ);
    46     obj.pushKV("name", wallet->GetName());
    47-    obj.pushKV("warning", Join(warnings, std::string("\n"), OpOriginal));
    48+    obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
    49 
    50     return obj;
    51 }
    52@@ -2737,7 +2737,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
    53 
    54     UniValue obj(UniValue::VOBJ);
    55     obj.pushKV("name", wallet->GetName());
    56-    obj.pushKV("warning", Join(warnings, std::string("\n"), OpOriginal));
    57+    obj.pushKV("warning", Join(warnings, "\n", OpOriginal));
    58 
    59     return obj;
    60 }
    

    hebasto commented at 1:49 pm on May 10, 2020:
    You are right. Those are remnants from the previous version of this branch.

    hebasto commented at 1:51 pm on May 10, 2020:
  18. hebasto force-pushed on May 10, 2020
  19. hebasto commented at 1:51 pm on May 10, 2020: member

    Updated 3ddfa414787e017d9760b2ac55517986673a4b1c -> 48710740c6f1cfa37c20545d0d6179d5de4bae6e (pr18922.03 -> pr18922.04, diff):

  20. util: Enhance Join() 4c9b9a4882
  21. gui: Do not translate InitWarning messages in debug.log da16f95c3f
  22. in src/logging.h:140 in 48710740c6 outdated
    136@@ -137,7 +137,7 @@ namespace BCLog {
    137         /** Returns a string with the log categories */
    138         std::string LogCategoriesString()
    139         {
    140-            return Join(LogCategoriesList(), ", ", [&](const LogCategory& i) { return i.category; });
    141+            return Join(LogCategoriesList(), std::string(", "), [&](const LogCategory& i) { return i.category; });
    


    MarcoFalke commented at 2:41 pm on May 10, 2020:
    Why is this one needed? (Sorry I missed it in my last review comment)

    hebasto commented at 3:14 pm on May 10, 2020:
    Thank you. Fixed.
  23. hebasto force-pushed on May 10, 2020
  24. hebasto commented at 3:13 pm on May 10, 2020: member

    Updated 48710740c6f1cfa37c20545d0d6179d5de4bae6e -> da16f95c3fecf4ee1e9a1dc4333b0b92cd981afd (pr18922.04 -> pr18922.05, diff):

    Why is this one needed? (Sorry I missed it in my last review comment)


    The current implementation of the Join() allows do not use OpOriginal and OpTranslated unary operators at all. Is it worth to drop them?

  25. MarcoFalke commented at 5:19 pm on May 10, 2020: member

    Is it worth to drop them?

    Up to you. I am happy to review either approach, as long as this is done in a new commit.

  26. util: Drop OpOriginal() and OpTranslated()
    The current implementation of the Join() allows do not use OpOriginal()
    and OpTranslated() unary operators at all.
    78be8d97d3
  27. hebasto commented at 6:30 pm on May 10, 2020: member
    Added commit which removes OpOriginal() and OpTranslated() unary operators.
  28. promag commented at 8:56 am on May 13, 2020: member
    Concept ACK, code looks fine.
  29. laanwj commented at 5:38 pm on May 13, 2020: member

    vladiation lol :joy:

    Looks good to me. Nice cleanup with the *Op functions.

    ACK 78be8d97d3d750fcfbbe509a72639b7b30b7bd18

    To have an idea of progress, I would like to know whether an end to this in in sight. Is InitWarning the last step? Or are there more functions after this that need to be converted to bilingual_str?

  30. jonasschnelli commented at 5:50 pm on May 13, 2020: contributor

    Have vladidated the code.

    utACK 78be8d97d3d750fcfbbe509a72639b7b30b7bd18

  31. MarcoFalke commented at 6:05 pm on May 13, 2020: member
    I think the last ones are AbortNode and the gui/rpc warnings #16218 (comment)
  32. MarcoFalke commented at 6:25 pm on May 13, 2020: member

    ACK 78be8d97d3d750fcfbbe509a72639b7b30b7bd18 📢

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 78be8d97d3d750fcfbbe509a72639b7b30b7bd18 📢
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUghsAv/TBQtsX9Zg+DSmubigFhi4U+8zCCTcrY+wH1oBCBcRVZdyDrgKQzWSQH5
     8f6fg99QfwzQYdhQd3Yykh1+YYTd0uHiUX/+YgRlaXpqNqvMoijMX/JjFgEOOKOCD
     9rueYNroFEqBChN79zQXj01/SIrVifVtIHzHQTbPsBkcQ6vUInOkQ9eBOpJZvkxro
    106WTC/APvUWZWS1F8prsxOR/t6a1YVg8RdjpKqfnQIxUYj/uPIVQfDYK5nhyo4Tao
    11FRmYA6pDoDsT3MYkDFDOCG/4dXyri8PTdVlqv2W0fyJ5fjGT1YGIyrMp56aILRlj
    12CtaIniMEj+gQIP2Aqn49hCzlYP7ljMg+IP5BVKBbPu4C0fCjf1QFPYyDMrUT2yP0
    13w1/7NXqEerOFDpTewkO0C/a96sGN/TpvjDr4uaZ4Svx32kF0pmhiLxy0qtjwL7Wg
    146iGt+m+yHDGPsJWzxDAlm+sJXzlUd3s2sQpDlqwv5afHASC5re38Vhc6OaqGt3lz
    15WrKEK80Y
    16=Eo5p
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash 69702236ca2cac943236ee37ffe813ced8a7bfccdd4b1792664d9fe1671d2185 -

  33. MarcoFalke commented at 6:25 pm on May 13, 2020: member
    @jonasschnelli Ready for merge?!
  34. jonasschnelli merged this on May 13, 2020
  35. jonasschnelli closed this on May 13, 2020

  36. sidhujag referenced this in commit 22afecdec6 on May 14, 2020
  37. hebasto deleted the branch on May 14, 2020
  38. deadalnix referenced this in commit db8a5bfdd2 on Dec 10, 2020
  39. kittywhiskers referenced this in commit f154f0ddb7 on May 25, 2021
  40. UdjinM6 referenced this in commit 33f09d0b35 on May 28, 2021
  41. 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 12:12 UTC

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