Skip to content

Commit 3b24c24

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 164017b commit 3b24c24

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
@@ -1206,7 +1206,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
12061206
try {
12071207
node.chainman = std::make_unique<ChainstateManager>(*Assert(node.shutdown_signal), chainman_opts, blockman_opts);
12081208
} catch (std::exception& e) {
1209-
return {ChainstateLoadStatus::FAILURE_FATAL, strprintf(Untranslated("Failed to initialize ChainstateManager: %s"), e.what())};
1209+
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated(strprintf("Failed to initialize ChainstateManager: %s", e.what()))};
12101210
}
12111211
ChainstateManager& chainman = *node.chainman;
12121212
// This is defined and set here instead of inline in validation.h to avoid a hard
@@ -1337,7 +1337,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13371337
try {
13381338
ipc->listenAddress(address);
13391339
} catch (const std::exception& e) {
1340-
return InitError(strprintf(Untranslated("Unable to bind to IPC address '%s'. %s"), address, e.what()));
1340+
return InitError(Untranslated(strprintf("Unable to bind to IPC address '%s'. %s", address, e.what())));
13411341
}
13421342
LogPrintf("Listening for IPC requests on address %s\n", address);
13431343
}
@@ -2042,7 +2042,7 @@ bool StartIndexBackgroundSync(NodeContext& node)
20422042
const CBlockIndex* start_block = *indexes_start_block;
20432043
if (!start_block) start_block = chainman.ActiveChain().Genesis();
20442044
if (!chainman.m_blockman.CheckBlockDataAvailability(*index_chain.Tip(), *Assert(start_block))) {
2045-
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));
2045+
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)));
20462046
}
20472047
}
20482048

src/init/common.cpp

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

118118
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
@@ -5697,20 +5697,20 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
56975697
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
56985698
auto available_heights = GetParams().GetAvailableSnapshotHeights();
56995699
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
5700-
return util::Error{strprintf(Untranslated("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s"),
5700+
return util::Error{Untranslated(strprintf("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s",
57015701
base_blockhash.ToString(),
5702-
heights_formatted)};
5702+
heights_formatted))};
57035703
}
57045704

57055705
snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash);
57065706
if (!snapshot_start_block) {
5707-
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"),
5708-
base_blockhash.ToString())};
5707+
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",
5708+
base_blockhash.ToString()))};
57095709
}
57105710

57115711
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
57125712
if (start_block_invalid) {
5713-
return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())};
5713+
return util::Error{Untranslated(strprintf("The base block header (%s) is part of an invalid chain", base_blockhash.ToString()))};
57145714
}
57155715

57165716
if (!m_best_header || m_best_header->GetAncestor(snapshot_start_block->nHeight) != snapshot_start_block) {
@@ -5870,16 +5870,16 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
58705870
if (!snapshot_start_block) {
58715871
// Needed for ComputeUTXOStats to determine the
58725872
// height and to avoid a crash when base_blockhash.IsNull()
5873-
return util::Error{strprintf(Untranslated("Did not find snapshot start blockheader %s"),
5874-
base_blockhash.ToString())};
5873+
return util::Error{Untranslated(strprintf("Did not find snapshot start blockheader %s",
5874+
base_blockhash.ToString()))};
58755875
}
58765876

58775877
int base_height = snapshot_start_block->nHeight;
58785878
const auto& maybe_au_data = GetParams().AssumeutxoForHeight(base_height);
58795879

58805880
if (!maybe_au_data) {
5881-
return util::Error{strprintf(Untranslated("Assumeutxo height in snapshot metadata not recognized "
5882-
"(%d) - refusing to load snapshot"), base_height)};
5881+
return util::Error{Untranslated(strprintf("Assumeutxo height in snapshot metadata not recognized "
5882+
"(%d) - refusing to load snapshot", base_height))};
58835883
}
58845884

58855885
const AssumeutxoData& au_data = *maybe_au_data;
@@ -5917,12 +5917,12 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59175917
if (coin.nHeight > base_height ||
59185918
outpoint.n >= std::numeric_limits<decltype(outpoint.n)>::max() // Avoid integer wrap-around in coinstats.cpp:ApplyHash
59195919
) {
5920-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins"),
5921-
coins_count - coins_left)};
5920+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins",
5921+
coins_count - coins_left))};
59225922
}
59235923
if (!MoneyRange(coin.out.nValue)) {
5924-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins - bad tx out value"),
5925-
coins_count - coins_left)};
5924+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins - bad tx out value",
5925+
coins_count - coins_left))};
59265926
}
59275927
coins_cache.EmplaceCoinInternalDANGER(std::move(outpoint), std::move(coin));
59285928

@@ -5960,8 +5960,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59605960
}
59615961
}
59625962
} catch (const std::ios_base::failure&) {
5963-
return util::Error{strprintf(Untranslated("Bad snapshot format or truncated snapshot after deserializing %d coins"),
5964-
coins_processed)};
5963+
return util::Error{Untranslated(strprintf("Bad snapshot format or truncated snapshot after deserializing %d coins",
5964+
coins_processed))};
59655965
}
59665966
}
59675967

@@ -5981,8 +5981,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59815981
out_of_coins = true;
59825982
}
59835983
if (!out_of_coins) {
5984-
return util::Error{strprintf(Untranslated("Bad snapshot - coins left over after deserializing %d coins"),
5985-
coins_count)};
5984+
return util::Error{Untranslated(strprintf("Bad snapshot - coins left over after deserializing %d coins",
5985+
coins_count))};
59865986
}
59875987

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

60146014
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
60156015
if (AssumeutxoHash{maybe_stats->hashSerialized} != au_data.hash_serialized) {
6016-
return util::Error{strprintf(Untranslated("Bad snapshot content hash: expected %s, got %s"),
6017-
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString())};
6016+
return util::Error{Untranslated(strprintf("Bad snapshot content hash: expected %s, got %s",
6017+
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString()))};
60186018
}
60196019

60206020
snapshot_chainstate.m_chain.SetTip(*snapshot_start_block);

0 commit comments

Comments
 (0)