Skip to content

Commit 0184d33

Browse files
committed
scripted-diff: Replace strprintf(Untranslated) with Untranslated(strprintf)
This makes code more consistent and makes it easier to add compile-time checking to enforce that format strings contain the right specifiers, because it stops using Untranslated() to create the format string, so the Untranslated() function will not need to get involved in formatting. -BEGIN VERIFY SCRIPT- quote='"[^"]+"' quotes="(?:$quote|\\s)*" nonparens="[^()]*" single_level_paren="\($nonparens\)" double_level_paren="\($nonparens\($nonparens\)$nonparens\)" exprs="(?:$double_level_paren|$single_level_paren|$nonparens)*" git grep -l 'Untranslated' | xargs perl -0777 -i -pe "s/strprintf\((\\W*)Untranslated\(($quotes)\)($exprs)(\))/Untranslated(\1strprintf(\2\3))/gs" -END VERIFY SCRIPT-
1 parent 006e4d1 commit 0184d33

File tree

13 files changed

+53
-53
lines changed

13 files changed

+53
-53
lines changed

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static bool InitHTTPAllowList()
227227
const CSubNet subnet{LookupSubNet(strAllow)};
228228
if (!subnet.IsValid()) {
229229
uiInterface.ThreadSafeMessageBox(
230-
strprintf(Untranslated("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24)."), strAllow),
230+
Untranslated(strprintf("Invalid -rpcallowip subnet specification: %s. Valid are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24).", strAllow)),
231231
"", CClientUIInterface::MSG_ERROR);
232232
return false;
233233
}

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bool BaseIndex::Init()
106106
// best chain, we will rewind to the fork point during index sync
107107
const CBlockIndex* locator_index{m_chainstate->m_blockman.LookupBlockIndex(locator.vHave.at(0))};
108108
if (!locator_index) {
109-
return InitError(strprintf(Untranslated("%s: best block of the index not found. Please rebuild the index."), GetName()));
109+
return InitError(Untranslated(strprintf("%s: best block of the index not found. Please rebuild the index.", GetName())));
110110
}
111111
SetBestBlockIndex(locator_index);
112112
}

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
12081208
try {
12091209
node.chainman = std::make_unique<ChainstateManager>(*Assert(node.shutdown_signal), chainman_opts, blockman_opts);
12101210
} catch (std::exception& e) {
1211-
return {ChainstateLoadStatus::FAILURE_FATAL, strprintf(Untranslated("Failed to initialize ChainstateManager: %s"), e.what())};
1211+
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated(strprintf("Failed to initialize ChainstateManager: %s", e.what()))};
12121212
}
12131213
ChainstateManager& chainman = *node.chainman;
12141214
// This is defined and set here instead of inline in validation.h to avoid a hard
@@ -1339,7 +1339,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13391339
try {
13401340
ipc->listenAddress(address);
13411341
} catch (const std::exception& e) {
1342-
return InitError(strprintf(Untranslated("Unable to bind to IPC address '%s'. %s"), address, e.what()));
1342+
return InitError(Untranslated(strprintf("Unable to bind to IPC address '%s'. %s", address, e.what())));
13431343
}
13441344
LogPrintf("Listening for IPC requests on address %s\n", address);
13451345
}
@@ -2044,7 +2044,7 @@ bool StartIndexBackgroundSync(NodeContext& node)
20442044
const CBlockIndex* start_block = *indexes_start_block;
20452045
if (!start_block) start_block = chainman.ActiveChain().Genesis();
20462046
if (!chainman.m_blockman.CheckBlockDataAvailability(*index_chain.Tip(), *Assert(start_block))) {
2047-
return InitError(strprintf(Untranslated("%s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"), older_index_name));
2047+
return InitError(Untranslated(strprintf("%s best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)", older_index_name)));
20482048
}
20492049
}
20502050

src/init/common.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ bool StartLogging(const ArgsManager& args)
112112
}
113113
}
114114
if (!LogInstance().StartLogging()) {
115-
return InitError(strprintf(Untranslated("Could not open debug log file %s"),
116-
fs::PathToString(LogInstance().m_file_path)));
115+
return InitError(Untranslated(strprintf("Could not open debug log file %s",
116+
fs::PathToString(LogInstance().m_file_path))));
117117
}
118118

119119
if (!LogInstance().m_log_timestamps)

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,22 +3058,22 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
30583058
socklen_t len = sizeof(sockaddr);
30593059
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
30603060
{
3061-
strError = strprintf(Untranslated("Bind address family for %s not supported"), addrBind.ToStringAddrPort());
3061+
strError = Untranslated(strprintf("Bind address family for %s not supported", addrBind.ToStringAddrPort()));
30623062
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
30633063
return false;
30643064
}
30653065

30663066
std::unique_ptr<Sock> sock = CreateSock(addrBind.GetSAFamily(), SOCK_STREAM, IPPROTO_TCP);
30673067
if (!sock) {
3068-
strError = strprintf(Untranslated("Couldn't open socket for incoming connections (socket returned error %s)"), NetworkErrorString(WSAGetLastError()));
3068+
strError = Untranslated(strprintf("Couldn't open socket for incoming connections (socket returned error %s)", NetworkErrorString(WSAGetLastError())));
30693069
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
30703070
return false;
30713071
}
30723072

30733073
// Allow binding if the port is still in TIME_WAIT state after
30743074
// the program was closed and restarted.
30753075
if (sock->SetSockOpt(SOL_SOCKET, SO_REUSEADDR, (sockopt_arg_type)&nOne, sizeof(int)) == SOCKET_ERROR) {
3076-
strError = strprintf(Untranslated("Error setting SO_REUSEADDR on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
3076+
strError = Untranslated(strprintf("Error setting SO_REUSEADDR on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
30773077
LogPrintf("%s\n", strError.original);
30783078
}
30793079

@@ -3082,14 +3082,14 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
30823082
if (addrBind.IsIPv6()) {
30833083
#ifdef IPV6_V6ONLY
30843084
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_V6ONLY, (sockopt_arg_type)&nOne, sizeof(int)) == SOCKET_ERROR) {
3085-
strError = strprintf(Untranslated("Error setting IPV6_V6ONLY on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
3085+
strError = Untranslated(strprintf("Error setting IPV6_V6ONLY on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
30863086
LogPrintf("%s\n", strError.original);
30873087
}
30883088
#endif
30893089
#ifdef WIN32
30903090
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
30913091
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)) == SOCKET_ERROR) {
3092-
strError = strprintf(Untranslated("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
3092+
strError = Untranslated(strprintf("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
30933093
LogPrintf("%s\n", strError.original);
30943094
}
30953095
#endif

src/node/chainstatemanager_args.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
3535
if (auto min_work{uint256::FromUserHex(*value)}) {
3636
opts.minimum_chain_work = UintToArith256(*min_work);
3737
} else {
38-
return util::Error{strprintf(Untranslated("Invalid minimum work specified (%s), must be up to %d hex digits"), *value, uint256::size() * 2)};
38+
return util::Error{Untranslated(strprintf("Invalid minimum work specified (%s), must be up to %d hex digits", *value, uint256::size() * 2))};
3939
}
4040
}
4141

4242
if (auto value{args.GetArg("-assumevalid")}) {
4343
if (auto block_hash{uint256::FromUserHex(*value)}) {
4444
opts.assumed_valid_block = *block_hash;
4545
} else {
46-
return util::Error{strprintf(Untranslated("Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable)"), *value, uint256::size() * 2)};
46+
return util::Error{Untranslated(strprintf("Invalid assumevalid block hash specified (%s), must be up to %d hex digits (or 0 to disable)", *value, uint256::size() * 2))};
4747
}
4848
}
4949

src/node/mempool_args.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& argsman, const CChainP
8989

9090
mempool_opts.require_standard = !argsman.GetBoolArg("-acceptnonstdtxn", DEFAULT_ACCEPT_NON_STD_TXN);
9191
if (!chainparams.IsTestChain() && !mempool_opts.require_standard) {
92-
return util::Error{strprintf(Untranslated("acceptnonstdtxn is not currently supported for %s chain"), chainparams.GetChainTypeString())};
92+
return util::Error{Untranslated(strprintf("acceptnonstdtxn is not currently supported for %s chain", chainparams.GetChainTypeString()))};
9393
}
9494

9595
mempool_opts.persist_v1_dat = argsman.GetBoolArg("-persistmempoolv1", mempool_opts.persist_v1_dat);

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ int GuiMain(int argc, char* argv[])
529529
SetupUIArgs(gArgs);
530530
std::string error;
531531
if (!gArgs.ParseParameters(argc, argv, error)) {
532-
InitError(strprintf(Untranslated("Error parsing command line arguments: %s"), error));
532+
InitError(Untranslated(strprintf("Error parsing command line arguments: %s", error)));
533533
// Create a message box, because the gui has neither been created nor has subscribed to core signals
534534
QMessageBox::critical(nullptr, CLIENT_NAME,
535535
// message cannot be translated because translations have not been initialized

src/test/result_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ util::Result<int> IntFn(int i, bool success)
4242
util::Result<bilingual_str> StrFn(bilingual_str s, bool success)
4343
{
4444
if (success) return s;
45-
return util::Error{strprintf(Untranslated("str %s error."), s.original)};
45+
return util::Error{Untranslated(strprintf("str %s error.", s.original))};
4646
}
4747

4848
util::Result<NoCopy> NoCopyFn(int i, bool success)

src/validation.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5719,20 +5719,20 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
57195719
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
57205720
auto available_heights = GetParams().GetAvailableSnapshotHeights();
57215721
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
5722-
return util::Error{strprintf(Untranslated("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s"),
5722+
return util::Error{Untranslated(strprintf("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s",
57235723
base_blockhash.ToString(),
5724-
heights_formatted)};
5724+
heights_formatted))};
57255725
}
57265726

57275727
snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash);
57285728
if (!snapshot_start_block) {
5729-
return util::Error{strprintf(Untranslated("The base block header (%s) must appear in the headers chain. Make sure all headers are syncing, and call loadtxoutset again"),
5730-
base_blockhash.ToString())};
5729+
return util::Error{Untranslated(strprintf("The base block header (%s) must appear in the headers chain. Make sure all headers are syncing, and call loadtxoutset again",
5730+
base_blockhash.ToString()))};
57315731
}
57325732

57335733
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
57345734
if (start_block_invalid) {
5735-
return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())};
5735+
return util::Error{Untranslated(strprintf("The base block header (%s) is part of an invalid chain", base_blockhash.ToString()))};
57365736
}
57375737

57385738
if (!m_best_header || m_best_header->GetAncestor(snapshot_start_block->nHeight) != snapshot_start_block) {
@@ -5892,16 +5892,16 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
58925892
if (!snapshot_start_block) {
58935893
// Needed for ComputeUTXOStats to determine the
58945894
// height and to avoid a crash when base_blockhash.IsNull()
5895-
return util::Error{strprintf(Untranslated("Did not find snapshot start blockheader %s"),
5896-
base_blockhash.ToString())};
5895+
return util::Error{Untranslated(strprintf("Did not find snapshot start blockheader %s",
5896+
base_blockhash.ToString()))};
58975897
}
58985898

58995899
int base_height = snapshot_start_block->nHeight;
59005900
const auto& maybe_au_data = GetParams().AssumeutxoForHeight(base_height);
59015901

59025902
if (!maybe_au_data) {
5903-
return util::Error{strprintf(Untranslated("Assumeutxo height in snapshot metadata not recognized "
5904-
"(%d) - refusing to load snapshot"), base_height)};
5903+
return util::Error{Untranslated(strprintf("Assumeutxo height in snapshot metadata not recognized "
5904+
"(%d) - refusing to load snapshot", base_height))};
59055905
}
59065906

59075907
const AssumeutxoData& au_data = *maybe_au_data;
@@ -5939,12 +5939,12 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59395939
if (coin.nHeight > base_height ||
59405940
outpoint.n >= std::numeric_limits<decltype(outpoint.n)>::max() // Avoid integer wrap-around in coinstats.cpp:ApplyHash
59415941
) {
5942-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins"),
5943-
coins_count - coins_left)};
5942+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins",
5943+
coins_count - coins_left))};
59445944
}
59455945
if (!MoneyRange(coin.out.nValue)) {
5946-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins - bad tx out value"),
5947-
coins_count - coins_left)};
5946+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins - bad tx out value",
5947+
coins_count - coins_left))};
59485948
}
59495949
coins_cache.EmplaceCoinInternalDANGER(std::move(outpoint), std::move(coin));
59505950

@@ -5982,8 +5982,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59825982
}
59835983
}
59845984
} catch (const std::ios_base::failure&) {
5985-
return util::Error{strprintf(Untranslated("Bad snapshot format or truncated snapshot after deserializing %d coins"),
5986-
coins_processed)};
5985+
return util::Error{Untranslated(strprintf("Bad snapshot format or truncated snapshot after deserializing %d coins",
5986+
coins_processed))};
59875987
}
59885988
}
59895989

@@ -6003,8 +6003,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
60036003
out_of_coins = true;
60046004
}
60056005
if (!out_of_coins) {
6006-
return util::Error{strprintf(Untranslated("Bad snapshot - coins left over after deserializing %d coins"),
6007-
coins_count)};
6006+
return util::Error{Untranslated(strprintf("Bad snapshot - coins left over after deserializing %d coins",
6007+
coins_count))};
60086008
}
60096009

60106010
LogPrintf("[snapshot] loaded %d (%.2f MB) coins from snapshot %s\n",
@@ -6035,8 +6035,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
60356035

60366036
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
60376037
if (AssumeutxoHash{maybe_stats->hashSerialized} != au_data.hash_serialized) {
6038-
return util::Error{strprintf(Untranslated("Bad snapshot content hash: expected %s, got %s"),
6039-
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString())};
6038+
return util::Error{Untranslated(strprintf("Bad snapshot content hash: expected %s, got %s",
6039+
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString()))};
60406040
}
60416041

60426042
snapshot_chainstate.m_chain.SetTip(*snapshot_start_block);

0 commit comments

Comments
 (0)