Skip to content

Commit d5a8e2b

Browse files
committed
scripted-diff: Replace strprintf(Untranslated) with Untranslated(strprintf)
An upcoming commit which adds compile time checking for format strings that are translated will drop support for formatting arbitrary bilingual_str like the Untranslated() results which are formatted here. -BEGIN VERIFY SCRIPT- quote='"[^"]+"' quotes="(?:$quote|\\W)*" 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 ab4e567 commit d5a8e2b

File tree

13 files changed

+54
-54
lines changed

13 files changed

+54
-54
lines changed

src/httpserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ static bool InitHTTPAllowList()
229229
const CSubNet subnet{LookupSubNet(strAllow)};
230230
if (!subnet.IsValid()) {
231231
uiInterface.ThreadSafeMessageBox(
232-
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),
232+
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)),
233233
"", CClientUIInterface::MSG_ERROR);
234234
return false;
235235
}

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
@@ -1220,7 +1220,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
12201220
try {
12211221
node.chainman = std::make_unique<ChainstateManager>(*Assert(node.shutdown), chainman_opts, blockman_opts);
12221222
} catch (std::exception& e) {
1223-
return {ChainstateLoadStatus::FAILURE_FATAL, strprintf(Untranslated("Failed to initialize ChainstateManager: %s"), e.what())};
1223+
return {ChainstateLoadStatus::FAILURE_FATAL, Untranslated(strprintf("Failed to initialize ChainstateManager: %s", e.what()))};
12241224
}
12251225
ChainstateManager& chainman = *node.chainman;
12261226
// This is defined and set here instead of inline in validation.h to avoid a hard
@@ -1351,7 +1351,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13511351
try {
13521352
ipc->listenAddress(address);
13531353
} catch (const std::exception& e) {
1354-
return InitError(strprintf(Untranslated("Unable to bind to IPC address '%s'. %s"), address, e.what()));
1354+
return InitError(Untranslated(strprintf("Unable to bind to IPC address '%s'. %s", address, e.what())));
13551355
}
13561356
LogPrintf("Listening for IPC requests on address %s\n", address);
13571357
}
@@ -2070,7 +2070,7 @@ bool StartIndexBackgroundSync(NodeContext& node)
20702070
const CBlockIndex* start_block = *indexes_start_block;
20712071
if (!start_block) start_block = chainman.ActiveChain().Genesis();
20722072
if (!chainman.m_blockman.CheckBlockDataAvailability(*index_chain.Tip(), *Assert(start_block))) {
2073-
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));
2073+
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)));
20742074
}
20752075
}
20762076

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
@@ -3054,22 +3054,22 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
30543054
socklen_t len = sizeof(sockaddr);
30553055
if (!addrBind.GetSockAddr((struct sockaddr*)&sockaddr, &len))
30563056
{
3057-
strError = strprintf(Untranslated("Bind address family for %s not supported"), addrBind.ToStringAddrPort());
3057+
strError = Untranslated(strprintf("Bind address family for %s not supported", addrBind.ToStringAddrPort()));
30583058
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", strError.original);
30593059
return false;
30603060
}
30613061

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

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

@@ -3078,14 +3078,14 @@ bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError,
30783078
if (addrBind.IsIPv6()) {
30793079
#ifdef IPV6_V6ONLY
30803080
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_V6ONLY, (sockopt_arg_type)&nOne, sizeof(int)) == SOCKET_ERROR) {
3081-
strError = strprintf(Untranslated("Error setting IPV6_V6ONLY on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
3081+
strError = Untranslated(strprintf("Error setting IPV6_V6ONLY on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
30823082
LogPrintf("%s\n", strError.original);
30833083
}
30843084
#endif
30853085
#ifdef WIN32
30863086
int nProtLevel = PROTECTION_LEVEL_UNRESTRICTED;
30873087
if (sock->SetSockOpt(IPPROTO_IPV6, IPV6_PROTECTION_LEVEL, (const char*)&nProtLevel, sizeof(int)) == SOCKET_ERROR) {
3088-
strError = strprintf(Untranslated("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway"), NetworkErrorString(WSAGetLastError()));
3088+
strError = Untranslated(strprintf("Error setting IPV6_PROTECTION_LEVEL on socket: %s, continuing anyway", NetworkErrorString(WSAGetLastError())));
30893089
LogPrintf("%s\n", strError.original);
30903090
}
30913091
#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.full_rbf = argsman.GetBoolArg("-mempoolfullrbf", mempool_opts.full_rbf);

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, PACKAGE_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: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5668,20 +5668,20 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
56685668
if (!GetParams().AssumeutxoForBlockhash(base_blockhash).has_value()) {
56695669
auto available_heights = GetParams().GetAvailableSnapshotHeights();
56705670
std::string heights_formatted = util::Join(available_heights, ", ", [&](const auto& i) { return util::ToString(i); });
5671-
return util::Error{strprintf(Untranslated("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s"),
5671+
return util::Error{Untranslated(strprintf("assumeutxo block hash in snapshot metadata not recognized (hash: %s). The following snapshot heights are available: %s",
56725672
base_blockhash.ToString(),
5673-
heights_formatted)};
5673+
heights_formatted))};
56745674
}
56755675

56765676
snapshot_start_block = m_blockman.LookupBlockIndex(base_blockhash);
56775677
if (!snapshot_start_block) {
5678-
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"),
5679-
base_blockhash.ToString())};
5678+
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",
5679+
base_blockhash.ToString()))};
56805680
}
56815681

56825682
bool start_block_invalid = snapshot_start_block->nStatus & BLOCK_FAILED_MASK;
56835683
if (start_block_invalid) {
5684-
return util::Error{strprintf(Untranslated("The base block header (%s) is part of an invalid chain"), base_blockhash.ToString())};
5684+
return util::Error{Untranslated(strprintf("The base block header (%s) is part of an invalid chain", base_blockhash.ToString()))};
56855685
}
56865686

56875687
if (!m_best_header || m_best_header->GetAncestor(snapshot_start_block->nHeight) != snapshot_start_block) {
@@ -5760,7 +5760,7 @@ util::Result<CBlockIndex*> ChainstateManager::ActivateSnapshot(
57605760

57615761
if (auto res{this->PopulateAndValidateSnapshot(*snapshot_chainstate, coins_file, metadata)}; !res) {
57625762
LOCK(::cs_main);
5763-
return cleanup_bad_snapshot(strprintf(Untranslated("Population failed: %s"), util::ErrorString(res).original));
5763+
return cleanup_bad_snapshot(Untranslated(strprintf("Population failed: %s", util::ErrorString(res).original)));
57645764
}
57655765

57665766
LOCK(::cs_main); // cs_main required for rest of snapshot activation.
@@ -5841,16 +5841,16 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
58415841
if (!snapshot_start_block) {
58425842
// Needed for ComputeUTXOStats to determine the
58435843
// height and to avoid a crash when base_blockhash.IsNull()
5844-
return util::Error{strprintf(Untranslated("Did not find snapshot start blockheader %s"),
5845-
base_blockhash.ToString())};
5844+
return util::Error{Untranslated(strprintf("Did not find snapshot start blockheader %s",
5845+
base_blockhash.ToString()))};
58465846
}
58475847

58485848
int base_height = snapshot_start_block->nHeight;
58495849
const auto& maybe_au_data = GetParams().AssumeutxoForHeight(base_height);
58505850

58515851
if (!maybe_au_data) {
5852-
return util::Error{strprintf(Untranslated("Assumeutxo height in snapshot metadata not recognized "
5853-
"(%d) - refusing to load snapshot"), base_height)};
5852+
return util::Error{Untranslated(strprintf("Assumeutxo height in snapshot metadata not recognized "
5853+
"(%d) - refusing to load snapshot", base_height))};
58545854
}
58555855

58565856
const AssumeutxoData& au_data = *maybe_au_data;
@@ -5888,12 +5888,12 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
58885888
if (coin.nHeight > base_height ||
58895889
outpoint.n >= std::numeric_limits<decltype(outpoint.n)>::max() // Avoid integer wrap-around in coinstats.cpp:ApplyHash
58905890
) {
5891-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins"),
5892-
coins_count - coins_left)};
5891+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins",
5892+
coins_count - coins_left))};
58935893
}
58945894
if (!MoneyRange(coin.out.nValue)) {
5895-
return util::Error{strprintf(Untranslated("Bad snapshot data after deserializing %d coins - bad tx out value"),
5896-
coins_count - coins_left)};
5895+
return util::Error{Untranslated(strprintf("Bad snapshot data after deserializing %d coins - bad tx out value",
5896+
coins_count - coins_left))};
58975897
}
58985898
coins_cache.EmplaceCoinInternalDANGER(std::move(outpoint), std::move(coin));
58995899

@@ -5931,8 +5931,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59315931
}
59325932
}
59335933
} catch (const std::ios_base::failure&) {
5934-
return util::Error{strprintf(Untranslated("Bad snapshot format or truncated snapshot after deserializing %d coins"),
5935-
coins_processed)};
5934+
return util::Error{Untranslated(strprintf("Bad snapshot format or truncated snapshot after deserializing %d coins",
5935+
coins_processed))};
59365936
}
59375937
}
59385938

@@ -5952,8 +5952,8 @@ util::Result<void> ChainstateManager::PopulateAndValidateSnapshot(
59525952
out_of_coins = true;
59535953
}
59545954
if (!out_of_coins) {
5955-
return util::Error{strprintf(Untranslated("Bad snapshot - coins left over after deserializing %d coins"),
5956-
coins_count)};
5955+
return util::Error{Untranslated(strprintf("Bad snapshot - coins left over after deserializing %d coins",
5956+
coins_count))};
59575957
}
59585958

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

59855985
// Assert that the deserialized chainstate contents match the expected assumeutxo value.
59865986
if (AssumeutxoHash{maybe_stats->hashSerialized} != au_data.hash_serialized) {
5987-
return util::Error{strprintf(Untranslated("Bad snapshot content hash: expected %s, got %s"),
5988-
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString())};
5987+
return util::Error{Untranslated(strprintf("Bad snapshot content hash: expected %s, got %s",
5988+
au_data.hash_serialized.ToString(), maybe_stats->hashSerialized.ToString()))};
59895989
}
59905990

59915991
snapshot_chainstate.m_chain.SetTip(*snapshot_start_block);

0 commit comments

Comments
 (0)