diff --git a/src/libxrpl/basics/FileUtilities.cpp b/src/libxrpl/basics/FileUtilities.cpp index bed2b756ac..a1c8adb6d7 100644 --- a/src/libxrpl/basics/FileUtilities.cpp +++ b/src/libxrpl/basics/FileUtilities.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -99,12 +100,13 @@ uniqueRandomPath( if (ec) { Throw( - "Unable to check path '" + candidate.string() + "': " + ec.message()); + std::format("Unable to check path '{}': {}", candidate.string(), ec.message())); } if (!exists) return candidate; } - Throw("Unable to generate a unique path under '" + base.string() + "'"); + Throw( + std::format("Unable to generate a unique path under '{}'", base.string())); } TempDir::TempDir() : path_(uniqueRandomPath(std::filesystem::temp_directory_path())) diff --git a/src/libxrpl/ledger/OpenView.cpp b/src/libxrpl/ledger/OpenView.cpp index 537b15c0d4..ae56f62fa2 100644 --- a/src/libxrpl/ledger/OpenView.cpp +++ b/src/libxrpl/ledger/OpenView.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -264,7 +265,7 @@ OpenView::rawTxInsert( auto const result = txs_.emplace( std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(txn, metaData)); if (!result.second) - Throw("rawTxInsert: duplicate TX id: " + to_string(key)); + Throw(std::format("rawTxInsert: duplicate TX id: {}", to_string(key))); } } // namespace xrpl diff --git a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp index 1c81b52ae1..dbf89a8b10 100644 --- a/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp +++ b/src/libxrpl/ledger/helpers/NFTokenHelpers.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -394,9 +395,11 @@ removeToken(ApplyView& view, AccountID const& owner, UInt256 const& nftokenID, S if (!page2) { - Throw( - "page " + to_string(page1->key()) + " has a broken " + field.getName() + - " field pointing to " + to_string(*id)); + Throw(std::format( + "page {} has a broken {} field pointing to {}", + to_string(page1->key()), + field.getName(), + to_string(*id))); } } @@ -597,7 +600,7 @@ removeTokenOffersWithLimit(ApplyView& view, Keylet const& directory, std::size_t else { Throw( - "Offer " + to_string(offerIndexes[i]) + " cannot be deleted!"); + std::format("Offer {} cannot be deleted!", to_string(offerIndexes[i]))); } } @@ -734,9 +737,9 @@ repairNFTokenDirectoryLinks(ApplyView& view, AccountID const& owner) if (!newPrev) { // LCOV_EXCL_START - Throw( - "NFTokenPage directory for " + to_string(owner) + - " cannot be repaired. Unexpected link problem."); + Throw(std::format( + "NFTokenPage directory for {} cannot be repaired. Unexpected link problem.", + to_string(owner))); // LCOV_EXCL_STOP } newPrev->at(sfNextPageMin) = nextPage->key(); diff --git a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp index bde97957a0..e29709c909 100644 --- a/src/libxrpl/nodestore/backend/RocksDBFactory.cpp +++ b/src/libxrpl/nodestore/backend/RocksDBFactory.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -193,7 +194,7 @@ public: if (!s.ok()) { Throw( - std::string("Unable to set RocksDB bbt_options: ") + s.ToString()); + std::format("Unable to set RocksDB bbt_options: {}", s.ToString())); } } @@ -206,7 +207,7 @@ public: if (!s.ok()) { Throw( - std::string("Unable to set RocksDB options: ") + s.ToString()); + std::format("Unable to set RocksDB options: {}", s.ToString())); } } @@ -241,7 +242,7 @@ public: if (!status.ok() || (localDb == nullptr)) { Throw( - std::string("Unable to open/create RocksDB: ") + status.ToString()); + std::format("Unable to open/create RocksDB: {}", status.ToString())); } db.reset(localDb); } @@ -356,7 +357,7 @@ public: auto ret = db->Write(options, &wb); if (!ret.ok()) - Throw("storeBatch failed: " + ret.ToString()); + Throw(std::format("storeBatch failed: {}", ret.ToString())); } void diff --git a/src/libxrpl/protocol/Permissions.cpp b/src/libxrpl/protocol/Permissions.cpp index 1caf11d66c..e2d879c555 100644 --- a/src/libxrpl/protocol/Permissions.cpp +++ b/src/libxrpl/protocol/Permissions.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -105,8 +106,8 @@ Permission::Permission() if (type <= UINT16_MAX) { // LCOV_EXCL_START - Throw( - "Granular permission value must exceed the maximum uint16_t value: " + name); + Throw(std::format( + "Granular permission value must exceed the maximum uint16_t value: {}", name)); // LCOV_EXCL_STOP } } diff --git a/src/libxrpl/protocol/STAmount.cpp b/src/libxrpl/protocol/STAmount.cpp index 83b2983756..f0bb254aca 100644 --- a/src/libxrpl/protocol/STAmount.cpp +++ b/src/libxrpl/protocol/STAmount.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1193,8 +1194,7 @@ muldiv(std::uint64_t multiplier, std::uint64_t multiplicand, std::uint64_t divis if (ret > std::numeric_limits::max()) { Throw( - "overflow: (" + std::to_string(multiplier) + " * " + std::to_string(multiplicand) + - ") / " + std::to_string(divisor)); + std::format("overflow: ({} * {}) / {}", multiplier, multiplicand, divisor)); } return static_cast(ret); @@ -1215,9 +1215,8 @@ muldivRound( if (ret > std::numeric_limits::max()) { - Throw( - "overflow: ((" + std::to_string(multiplier) + " * " + std::to_string(multiplicand) + - ") + " + std::to_string(rounding) + ") / " + std::to_string(divisor)); + Throw(std::format( + "overflow: (({} * {}) + {}) / {}", multiplier, multiplicand, rounding, divisor)); } return static_cast(ret); diff --git a/src/libxrpl/protocol/STLedgerEntry.cpp b/src/libxrpl/protocol/STLedgerEntry.cpp index 748183ea81..03f9e01a2c 100644 --- a/src/libxrpl/protocol/STLedgerEntry.cpp +++ b/src/libxrpl/protocol/STLedgerEntry.cpp @@ -35,9 +35,8 @@ STLedgerEntry::STLedgerEntry(Keylet const& k) : STObject(sfLedgerEntry), key_(k. if (format == nullptr) { - Throw( - "Attempt to create a SLE of unknown type " + - std::to_string(safeCast(k.type))); + Throw(std::format( + "Attempt to create a SLE of unknown type {}", safeCast(k.type))); } set(format->getSOTemplate()); diff --git a/src/libxrpl/protocol/STNumber.cpp b/src/libxrpl/protocol/STNumber.cpp index 7bf98f270c..a641b3847a 100644 --- a/src/libxrpl/protocol/STNumber.cpp +++ b/src/libxrpl/protocol/STNumber.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -170,7 +171,7 @@ partsFromString(std::string const& number) boost::smatch match; if (!boost::regex_match(number, match, kReNumber)) - Throw("'" + number + "' is not a number"); + Throw(std::format("'{}' is not a number", number)); // Match fields: // 0 = whole input diff --git a/src/libxrpl/protocol/STTx.cpp b/src/libxrpl/protocol/STTx.cpp index 0f6e56c86b..1c01159bba 100644 --- a/src/libxrpl/protocol/STTx.cpp +++ b/src/libxrpl/protocol/STTx.cpp @@ -59,9 +59,8 @@ getTxFormat(TxType type) if (format == nullptr) { - Throw( - "Invalid transaction type " + - std::to_string(safeCast>(type))); + Throw(std::format( + "Invalid transaction type {}", safeCast>(type))); } return format; diff --git a/src/libxrpl/protocol/STVector256.cpp b/src/libxrpl/protocol/STVector256.cpp index f577ba20e8..9171f969f8 100644 --- a/src/libxrpl/protocol/STVector256.cpp +++ b/src/libxrpl/protocol/STVector256.cpp @@ -9,8 +9,8 @@ #include #include +#include #include -#include #include namespace xrpl { @@ -22,7 +22,7 @@ STVector256::STVector256(SerialIter& sit, SField const& name) : STBase(name) if (slice.size() % UInt256::size() != 0) { Throw( - "Bad serialization for STVector256: " + std::to_string(slice.size())); + std::format("Bad serialization for STVector256: {}", slice.size())); } auto const cnt = slice.size() / UInt256::size(); diff --git a/src/libxrpl/protocol/STXChainBridge.cpp b/src/libxrpl/protocol/STXChainBridge.cpp index f9f1fd1dcc..3c63980264 100644 --- a/src/libxrpl/protocol/STXChainBridge.cpp +++ b/src/libxrpl/protocol/STXChainBridge.cpp @@ -70,7 +70,8 @@ STXChainBridge::STXChainBridge(SField const& name, json::Value const& v) : STBas std::string const name = it.memberName(); if (!kBridgeJson.isMember(name)) { - Throw("STXChainBridge extra field detected: " + name); + Throw( + std::format("STXChainBridge extra field detected: {}", name)); } } return true; diff --git a/src/libxrpl/protocol/Serializer.cpp b/src/libxrpl/protocol/Serializer.cpp index 595fbc71da..b6e09d4697 100644 --- a/src/libxrpl/protocol/Serializer.cpp +++ b/src/libxrpl/protocol/Serializer.cpp @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include namespace xrpl { @@ -456,7 +456,7 @@ SerialIter::getFieldID(int& type, int& name) // uncommon type type = get8(); if (type < 16) - Throw("gFID: uncommon type out of range " + std::to_string(type)); + Throw(std::format("gFID: uncommon type out of range {}", type)); } if (name == 0) @@ -464,7 +464,7 @@ SerialIter::getFieldID(int& type, int& name) // uncommon name name = get8(); if (name < 16) - Throw("gFID: uncommon name out of range " + std::to_string(name)); + Throw(std::format("gFID: uncommon name out of range {}", name)); } } diff --git a/src/libxrpl/rdb/SociDB.cpp b/src/libxrpl/rdb/SociDB.cpp index 84006acbe7..12a5e0e296 100644 --- a/src/libxrpl/rdb/SociDB.cpp +++ b/src/libxrpl/rdb/SociDB.cpp @@ -27,6 +27,7 @@ #include // IWYU pragma: keep +#include #include namespace xrpl { @@ -40,8 +41,8 @@ getSociSqliteInit(std::string const& name, std::string const& dir, std::string c { if (name.empty()) { - Throw( - "Sqlite databases must specify a dir and a name. Name: " + name + " Dir: " + dir); + Throw(std::format( + "Sqlite databases must specify a dir and a name. Name: {} Dir: {}", name, dir)); } std::filesystem::path file(dir); if (std::filesystem::is_directory(file)) @@ -56,7 +57,7 @@ getSociInit(BasicConfig const& config, std::string const& dbName) auto const backendName = get(section, Keys::kBackend, "sqlite"); if (backendName != "sqlite") - Throw("Unsupported soci backend: " + backendName); + Throw(std::format("Unsupported soci backend: {}", backendName)); auto const path = config.legacy(Sections::kDatabasePath); auto const ext = dbName == "validators" || dbName == "peerfinder" ? ".sqlite" : ".db"; @@ -101,7 +102,7 @@ open(soci::session& s, std::string const& beName, std::string const& connectionS } else { - Throw("Unsupported soci backend: " + beName); + Throw(std::format("Unsupported soci backend: {}", beName)); } } diff --git a/src/libxrpl/server/Manifest.cpp b/src/libxrpl/server/Manifest.cpp index 0bedffcfce..a4837376c7 100644 --- a/src/libxrpl/server/Manifest.cpp +++ b/src/libxrpl/server/Manifest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ to_string(Manifest const& m) return "Revocation Manifest " + mk; if (!m.signingKey) - Throw("No SigningKey in manifest " + mk); + Throw(std::format("No SigningKey in manifest {}", mk)); return "Manifest " + mk + " (" + std::to_string(m.sequence) + ": " + toBase58(TokenType::NodePublic, *m.signingKey) + ")"; diff --git a/src/libxrpl/shamap/SHAMapNodeID.cpp b/src/libxrpl/shamap/SHAMapNodeID.cpp index 89e81ecd53..8e0287c73c 100644 --- a/src/libxrpl/shamap/SHAMapNodeID.cpp +++ b/src/libxrpl/shamap/SHAMapNodeID.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -107,10 +108,10 @@ SHAMapNodeID::getChildNodeID(unsigned int branch) const depth_ <= SHAMap::kLeafDepth, "xrpl::SHAMapNodeID::getChildNodeID : maximum leaf depth"); if (depth_ >= SHAMap::kLeafDepth) - Throw("Request for child node ID of " + to_string(*this)); + Throw(std::format("Request for child node ID of {}", to_string(*this))); if (!isPrefixOf(id_)) - Throw("Incorrect mask for " + to_string(*this)); + Throw(std::format("Incorrect mask for {}", to_string(*this))); SHAMapNodeID node{depth_ + 1, id_}; node.id_.begin()[depth_ / 2] |= ((depth_ & 1) != 0u) ? branch : (branch << 4); diff --git a/src/libxrpl/shamap/SHAMapTreeNode.cpp b/src/libxrpl/shamap/SHAMapTreeNode.cpp index 2e7dfd2cae..08d8a05d2d 100644 --- a/src/libxrpl/shamap/SHAMapTreeNode.cpp +++ b/src/libxrpl/shamap/SHAMapTreeNode.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -30,9 +31,8 @@ SHAMapTreeNode::makeTransaction(Slice data, SHAMapHash const& hash, bool hashVal { if (data.size() < kMinShaMapItemBytes) { - Throw( - "Short TXN node: " + std::to_string(data.size()) + " bytes (minimum " + - std::to_string(kMinShaMapItemBytes) + " required)"); + Throw(std::format( + "Short TXN node: {} bytes (minimum {} required)", data.size(), kMinShaMapItemBytes)); } auto item = makeShamapitem(sha512Half(HashPrefix::TransactionId, data), data); @@ -52,27 +52,25 @@ SHAMapTreeNode::makeTransactionWithMeta(Slice data, SHAMapHash const& hash, bool if (s.size() < tag.kBytes) { - Throw( - "Short TXN+MD node: " + std::to_string(s.size()) + " bytes (minimum " + - std::to_string(tag.kBytes) + " required for tag)"); + Throw(std::format( + "Short TXN+MD node: {} bytes (minimum {} required for tag)", s.size(), tag.kBytes)); } // FIXME: improve this interface so that the above check isn't needed if (!s.getBitString(tag, s.size() - tag.kBytes)) { - Throw( - "Short TXN+MD node: failed to read tag at offset " + - std::to_string(s.size() - tag.kBytes)); + Throw(std::format( + "Short TXN+MD node: failed to read tag at offset {}", s.size() - tag.kBytes)); } s.chop(tag.kBytes); if (s.size() < kMinShaMapItemBytes) { - Throw( - "Short TXN+MD node: " + std::to_string(s.size()) + - " bytes after tag removal (minimum " + std::to_string(kMinShaMapItemBytes) + - " required)"); + Throw(std::format( + "Short TXN+MD node: {} bytes after tag removal (minimum {} required)", + s.size(), + kMinShaMapItemBytes)); } auto item = makeShamapitem(tag, s.slice()); @@ -92,16 +90,15 @@ SHAMapTreeNode::makeAccountState(Slice data, SHAMapHash const& hash, bool hashVa if (s.size() < tag.kBytes) { - Throw( - "Short AS node: " + std::to_string(s.size()) + " bytes (minimum " + - std::to_string(tag.kBytes) + " required for tag)"); + Throw(std::format( + "Short AS node: {} bytes (minimum {} required for tag)", s.size(), tag.kBytes)); } // FIXME: improve this interface so that the above check isn't needed if (!s.getBitString(tag, s.size() - tag.kBytes)) { Throw( - "Short AS node: failed to read tag at offset " + std::to_string(s.size() - tag.kBytes)); + std::format("Short AS node: failed to read tag at offset {}", s.size() - tag.kBytes)); } s.chop(tag.kBytes); @@ -111,9 +108,10 @@ SHAMapTreeNode::makeAccountState(Slice data, SHAMapHash const& hash, bool hashVa if (s.size() < kMinShaMapItemBytes) { - Throw( - "Short AS node: " + std::to_string(s.size()) + " bytes after tag removal (minimum " + - std::to_string(kMinShaMapItemBytes) + " required)"); + Throw(std::format( + "Short AS node: {} bytes after tag removal (minimum {} required)", + s.size(), + kMinShaMapItemBytes)); } auto item = makeShamapitem(tag, s.slice()); @@ -152,7 +150,7 @@ SHAMapTreeNode::makeFromWire(Slice rawNode) if (type == kWireTypeTransactionWithMeta) return makeTransactionWithMeta(rawNode, hash, hashValid); - Throw("wire: Unknown type (" + std::to_string(type) + ")"); + Throw(std::format("wire: Unknown type ({})", type)); } SHAMapTreeNodePtr @@ -183,9 +181,8 @@ SHAMapTreeNode::makeFromPrefix(Slice rawNode, SHAMapHash const& hash) if (type == HashPrefix::TxNode) return makeTransactionWithMeta(rawNode, hash, hashValid); - Throw( - "prefix: unknown type (" + - std::to_string(safeCast>(type)) + ")"); + Throw(std::format( + "prefix: unknown type ({})", safeCast>(type))); } std::string diff --git a/src/xrpld/app/main/NodeIdentity.cpp b/src/xrpld/app/main/NodeIdentity.cpp index 8198c43af7..3892ff3c34 100644 --- a/src/xrpld/app/main/NodeIdentity.cpp +++ b/src/xrpld/app/main/NodeIdentity.cpp @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -38,7 +39,7 @@ getNodeIdentity(Application& app, boost::program_options::variables_map const& c if (!seed) { Throw( - std::string("Invalid [") + Sections::kNodeSeed + "] in configuration file"); + std::format("Invalid [{}] in configuration file", Sections::kNodeSeed)); } } diff --git a/src/xrpld/app/misc/SHAMapStoreImp.cpp b/src/xrpld/app/misc/SHAMapStoreImp.cpp index e19df597a2..5dd3129eb7 100644 --- a/src/xrpld/app/misc/SHAMapStoreImp.cpp +++ b/src/xrpld/app/misc/SHAMapStoreImp.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -110,7 +111,7 @@ SHAMapStoreImp::SHAMapStoreImp( if (section.empty()) { Throw( - std::string("Missing [") + Sections::kNodeDatabase + "] entry in configuration file"); + std::format("Missing [{}] entry in configuration file", Sections::kNodeDatabase)); } // RocksDB only. Use sensible defaults if no values specified. @@ -135,15 +136,14 @@ SHAMapStoreImp::SHAMapStoreImp( if (deleteInterval_ < minInterval) { Throw( - "online_delete must be at least " + std::to_string(minInterval)); + std::format("online_delete must be at least {}", minInterval)); } if (config.ledgerHistory > deleteInterval_) { - Throw( - "online_delete must not be less than ledger_history " - "(currently " + - std::to_string(config.ledgerHistory) + ")"); + Throw(std::format( + "online_delete must not be less than ledger_history (currently {})", + config.ledgerHistory)); } // Configuration that affects the behavior of online delete @@ -177,7 +177,7 @@ SHAMapStoreImp::SHAMapStoreImp( if (maxWaitingLedgers_ < minWaiting) { Throw( - "max_waiting_ledgers must be at least " + std::to_string(minWaiting)); + std::format("max_waiting_ledgers must be at least {}", minWaiting)); } stateDb_.init(config, dbName_); diff --git a/src/xrpld/app/misc/detail/AmendmentTable.cpp b/src/xrpld/app/misc/detail/AmendmentTable.cpp index 477e013c3b..e9c66f7817 100644 --- a/src/xrpld/app/misc/detail/AmendmentTable.cpp +++ b/src/xrpld/app/misc/detail/AmendmentTable.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -65,14 +66,17 @@ parseSection(Section const& section) boost::smatch match; if (!boost::regex_match(line, match, kRe1)) - Throw("Invalid entry '" + line + "' in [" + section.name() + "]"); + { + Throw( + std::format("Invalid entry '{}' in [{}]", line, section.name())); + } UInt256 id; if (!id.parseHex(match[1])) { Throw( - "Invalid amendment ID '" + match[1] + "' in [" + section.name() + "]"); + std::format("Invalid amendment ID '{}' in [{}]", match[1].str(), section.name())); } names.emplace_back(id, match[2]); @@ -614,7 +618,7 @@ AmendmentTableImpl::AmendmentTableImpl( if (!amendHash.parseHex(*amendmentHash)) { Throw( - "Invalid amendment ID '" + *amendmentHash + " in wallet.db"); + std::format("Invalid amendment ID '{}' in wallet.db", *amendmentHash)); } if (*vote == AmendmentVote::Down) { diff --git a/src/xrpld/core/detail/Config.cpp b/src/xrpld/core/detail/Config.cpp index c280db63e3..876cffbce7 100644 --- a/src/xrpld/core/detail/Config.cpp +++ b/src/xrpld/core/detail/Config.cpp @@ -544,9 +544,10 @@ Config::loadFromString(std::string const& fileContents) peersInMaxOpt = beast::lexicalCastThrow(strTemp); if (*peersInMaxOpt > 1000) { - Throw( - std::string("Invalid value specified in [") + Sections::kPeersInMax + - "] section; the value must be less or equal than 1000"); + Throw(std::format( + "Invalid value specified in [{}] section; the value must be less or equal than " + "1000", + Sections::kPeersInMax)); } } @@ -556,18 +557,19 @@ Config::loadFromString(std::string const& fileContents) peersOutMaxOpt = beast::lexicalCastThrow(strTemp); if (*peersOutMaxOpt < 10 || *peersOutMaxOpt > 1000) { - Throw( - std::string("Invalid value specified in [") + Sections::kPeersOutMax + - "] section; the value must be in range 10-1000"); + Throw(std::format( + "Invalid value specified in [{}] section; the value must be in range 10-1000", + Sections::kPeersOutMax)); } } // if one section is configured then the other must be configured too if ((peersInMaxOpt && !peersOutMaxOpt) || (peersOutMaxOpt && !peersInMaxOpt)) { - Throw( - std::string("Both sections [") + Sections::kPeersInMax + "]" + " and [" + - Sections::kPeersOutMax + "] must be configured"); + Throw(std::format( + "Both sections [{}] and [{}] must be configured", + Sections::kPeersInMax, + Sections::kPeersOutMax)); } if (peersInMaxOpt && peersOutMaxOpt) @@ -633,9 +635,8 @@ Config::loadFromString(std::string const& fileContents) } else { - Throw( - std::string("Invalid value specified in [") + Sections::kRelayValidations + - "] section"); + Throw(std::format( + "Invalid value specified in [{}] section", Sections::kRelayValidations)); } } @@ -656,16 +657,16 @@ Config::loadFromString(std::string const& fileContents) else { Throw( - std::string("Invalid value specified in [") + Sections::kRelayProposals + - "] section"); + std::format("Invalid value specified in [{}] section", Sections::kRelayProposals)); } } if (exists(Sections::kValidationSeed) && exists(Sections::kValidatorToken)) { - Throw( - std::string("Cannot have both [") + Sections::kValidationSeed + "] and [" + - Sections::kValidatorToken + "] config sections"); + Throw(std::format( + "Cannot have both [{}] and [{}] config sections", + Sections::kValidationSeed, + Sections::kValidatorToken)); } if (getSingleSection(secConfig, Sections::kNetworkQuorum, strTemp, j_)) @@ -738,9 +739,8 @@ Config::loadFromString(std::string const& fileContents) if (sweepInterval < 10 || sweepInterval > 600) { - Throw( - std::string("Invalid ") + Sections::kSweepInterval + - ": must be between 10 and 600 inclusive"); + Throw(std::format( + "Invalid {}: must be between 10 and 600 inclusive", Sections::kSweepInterval)); } } @@ -750,9 +750,8 @@ Config::loadFromString(std::string const& fileContents) if (workers < 1 || workers > 1024) { - Throw( - std::string("Invalid ") + Sections::kWorkers + - ": must be between 1 and 1024 inclusive."); + Throw(std::format( + "Invalid {}: must be between 1 and 1024 inclusive.", Sections::kWorkers)); } } @@ -762,9 +761,8 @@ Config::loadFromString(std::string const& fileContents) if (ioWorkers < 1 || ioWorkers > 1024) { - Throw( - std::string("Invalid ") + Sections::kIoWorkers + - ": must be between 1 and 1024 inclusive."); + Throw(std::format( + "Invalid {}: must be between 1 and 1024 inclusive.", Sections::kIoWorkers)); } } @@ -774,9 +772,8 @@ Config::loadFromString(std::string const& fileContents) if (prefetchWorkers < 1 || prefetchWorkers > 1024) { - Throw( - std::string("Invalid ") + Sections::kPrefetchWorkers + - ": must be between 1 and 1024 inclusive."); + Throw(std::format( + "Invalid {}: must be between 1 and 1024 inclusive.", Sections::kPrefetchWorkers)); } } @@ -800,12 +797,10 @@ Config::loadFromString(std::string const& fileContents) // sec.value_or("vp_base_squelch_enable", true); // if (sec.exists(Keys::kVpBaseSquelchEnable) && sec.exists(Keys::kVpEnable)) { - Throw( - std::string("Invalid ") + Sections::kReduceRelay + - " cannot specify both vp_base_squelch_enable and vp_enable " - "options. " - "vp_enable was deprecated and replaced by " - "vp_base_squelch_enable"); + Throw(std::format( + "Invalid {} cannot specify both vp_base_squelch_enable and vp_enable options. " + "vp_enable was deprecated and replaced by vp_base_squelch_enable", + Sections::kReduceRelay)); } if (sec.exists(Keys::kVpBaseSquelchEnable)) @@ -833,10 +828,9 @@ Config::loadFromString(std::string const& fileContents) vpReduceRelaySquelchMaxSelectedPeers = sec.valueOr(Keys::kVpBaseSquelchMaxSelectedPeers, 5); if (vpReduceRelaySquelchMaxSelectedPeers < 3) { - Throw( - std::string("Invalid ") + Sections::kReduceRelay + - " vp_base_squelch_max_selected_peers must be " - "greater than or equal to 3"); + Throw(std::format( + "Invalid {} vp_base_squelch_max_selected_peers must be greater than or equal to 3", + Sections::kReduceRelay)); } /** * ////////////// !!END OF TEMPORARY CODE BLOCK!! ///////////////////// @@ -848,11 +842,10 @@ Config::loadFromString(std::string const& fileContents) txRelayPercentage = sec.valueOr(Keys::kTxRelayPercentage, 25); if (txRelayPercentage < 10 || txRelayPercentage > 100 || txReduceRelayMinPeers < 10) { - Throw( - std::string("Invalid ") + Sections::kReduceRelay + - ", tx_min_peers must be greater than or equal to 10" - ", tx_relay_percentage must be greater than or equal to 10 " - "and less than or equal to 100"); + Throw(std::format( + "Invalid {}, tx_min_peers must be greater than or equal to 10, tx_relay_percentage " + "must be greater than or equal to 10 and less than or equal to 100", + Sections::kReduceRelay)); } } @@ -866,9 +859,9 @@ Config::loadFromString(std::string const& fileContents) { if (!isProperlyFormedTomlDomain(strTemp)) { - Throw( - std::string("Invalid ") + Sections::kServerDomain + - ": the domain name does not appear to meet the requirements."); + Throw(std::format( + "Invalid {}: the domain name does not appear to meet the requirements.", + Sections::kServerDomain)); } serverDomain = strTemp; @@ -887,16 +880,18 @@ Config::loadFromString(std::string const& fileContents) } catch (...) { - Throw( - std::string("Invalid value 'max_unknown_time' in ") + Sections::kOverlay + - ": must be of the form '' representing seconds."); + Throw(std::format( + "Invalid value 'max_unknown_time' in {}: must be of the form '' " + "representing seconds.", + Sections::kOverlay)); } if (maxUnknownTime < seconds{300} || maxUnknownTime > seconds{1800}) { - Throw( - std::string("Invalid value 'max_unknown_time' in ") + Sections::kOverlay + - ": the time must be between 300 and 1800 seconds, inclusive."); + Throw(std::format( + "Invalid value 'max_unknown_time' in {}: the time must be between 300 and 1800 " + "seconds, inclusive.", + Sections::kOverlay)); } try @@ -906,16 +901,18 @@ Config::loadFromString(std::string const& fileContents) } catch (...) { - Throw( - std::string("Invalid value 'max_diverged_time' in ") + Sections::kOverlay + - ": must be of the form '' representing seconds."); + Throw(std::format( + "Invalid value 'max_diverged_time' in {}: must be of the form '' " + "representing seconds.", + Sections::kOverlay)); } if (maxDivergedTime < seconds{60} || maxDivergedTime > seconds{900}) { - Throw( - std::string("Invalid value 'max_diverged_time' in ") + Sections::kOverlay + - ": the time must be between 60 and 900 seconds, inclusive."); + Throw(std::format( + "Invalid value 'max_diverged_time' in {}: the time must be between 60 and 900 " + "seconds, inclusive.", + Sections::kOverlay)); } // Both manifest counts parse and validate identically, so read them @@ -931,17 +928,21 @@ Config::loadFromString(std::string const& fileContents) } catch (...) { - Throw( - std::string("Invalid value '") + key + "' in " + Sections::kOverlay + - ": must be of the form '' representing a count of manifests."); + Throw(std::format( + "Invalid value '{}' in {}: must be of the form '' representing a count " + "of manifests.", + key, + Sections::kOverlay)); } if (count && (*count < kMinManifestCount || *count > kMaxManifestCount)) { - Throw( - std::string("Invalid value '") + key + "' in " + Sections::kOverlay + - ": the count must be between " + std::to_string(kMinManifestCount) + " and " + - std::to_string(kMaxManifestCount) + ", inclusive."); + Throw(std::format( + "Invalid value '{}' in {}: the count must be between {} and {}, inclusive.", + key, + Sections::kOverlay, + kMinManifestCount, + kMaxManifestCount)); } return count; @@ -958,9 +959,9 @@ Config::loadFromString(std::string const& fileContents) boost::smatch match; if (!boost::regex_match(strTemp, match, re)) { - Throw( - std::string("Invalid ") + Sections::kAmendmentMajorityTime + - ", must be: [0-9]+ [minutes|hours|days|weeks]"); + Throw(std::format( + "Invalid {}, must be: [0-9]+ [minutes|hours|days|weeks]", + Sections::kAmendmentMajorityTime)); } auto const duration = beast::lexicalCastThrow(match[1].str()); @@ -984,10 +985,10 @@ Config::loadFromString(std::string const& fileContents) if (amendmentMajorityTime < minutes(15)) { - Throw( - std::string("Invalid ") + Sections::kAmendmentMajorityTime + - ", the minimum amount of time an amendment must hold a " - "majority is 15 minutes"); + Throw(std::format( + "Invalid {}, the minimum amount of time an amendment must hold a majority is 15 " + "minutes", + Sections::kAmendmentMajorityTime)); } } @@ -1014,7 +1015,7 @@ Config::loadFromString(std::string const& fileContents) if (validatorsFile.empty()) { Throw( - std::string("Invalid path specified in [") + Sections::kValidatorsFile + "]"); + std::format("Invalid path specified in [{}]", Sections::kValidatorsFile)); } if (!validatorsFile.is_absolute() && !configDir.empty()) @@ -1022,19 +1023,19 @@ Config::loadFromString(std::string const& fileContents) if (!std::filesystem::exists(validatorsFile)) { - Throw( - std::string("The file specified in [") + Sections::kValidatorsFile + - "] " - "does not exist: " + - validatorsFile.string()); + Throw(std::format( + "The file specified in [{}] does not exist: {}", + Sections::kValidatorsFile, + validatorsFile.string())); } else if ( !std::filesystem::is_regular_file(validatorsFile) && !std::filesystem::is_symlink(validatorsFile)) { - Throw( - std::string("Invalid file specified in [") + Sections::kValidatorsFile + - "]: " + validatorsFile.string()); + Throw(std::format( + "Invalid file specified in [{}]: {}", + Sections::kValidatorsFile, + validatorsFile.string())); } } else if (!configDir.empty()) @@ -1060,9 +1061,11 @@ Config::loadFromString(std::string const& fileContents) auto const data = getFileContents(ec, validatorsFile); if (ec) { - Throw( - "Failed to read '" + validatorsFile.string() + "'." + - std::to_string(ec.value()) + ": " + ec.message()); + Throw(std::format( + "Failed to read '{}': {} (error {})", + validatorsFile.string(), + ec.message(), + ec.value())); } auto iniFile = parseIniFile(data, true); @@ -1094,20 +1097,13 @@ Config::loadFromString(std::string const& fileContents) if ((entries == nullptr) && (valKeyEntries == nullptr) && (valListKeys == nullptr)) { - Throw( - std::string("The file specified in [") + Sections::kValidatorsFile + - "] " - "does not contain a [" + - Sections::kValidators + - "], " - "[" + - Sections::kValidatorKeys + - "] or " - "[" + - Sections::kValidatorListKeys + - "]" - " section: " + - validatorsFile.string()); + Throw(std::format( + "The file specified in [{}] does not contain a [{}], [{}] or [{}] section: {}", + Sections::kValidatorsFile, + Sections::kValidators, + Sections::kValidatorKeys, + Sections::kValidatorListKeys, + validatorsFile.string())); } } @@ -1127,21 +1123,16 @@ Config::loadFromString(std::string const& fileContents) } if (listThreshold > section(Sections::kValidatorListKeys).values().size()) { - Throw( - std::string( - "Value in config section " - "[") + - Sections::kValidatorListThreshold + - "] exceeds the number of configured list keys"); + Throw(std::format( + "Value in config section [{}] exceeds the number of configured list keys", + Sections::kValidatorListThreshold)); } return listThreshold; } - Throw( - std::string( - "Config section " - "[") + - Sections::kValidatorListThreshold + "] should contain single value only"); + Throw(std::format( + "Config section [{}] should contain single value only", + Sections::kValidatorListThreshold)); }(); // Consolidate [validator_keys] and [validators] @@ -1151,7 +1142,7 @@ Config::loadFromString(std::string const& fileContents) section(Sections::kValidatorListKeys).lines().empty()) { Throw( - "[" + std::string(Sections::kValidatorListKeys) + "] config section is missing"); + std::format("[{}] config section is missing", Sections::kValidatorListKeys)); } } @@ -1165,7 +1156,7 @@ Config::loadFromString(std::string const& fileContents) } else { - Throw("Unknown feature: " + s + " in config file."); + Throw(std::format("Unknown feature: {} in config file.", s)); } } } @@ -1290,7 +1281,8 @@ setupDatabaseCon(Config const& c, std::optional j) } else if (!boost::iequals(safetyLevel, "high")) { - Throw("Invalid safety_level value: " + safetyLevel); + Throw( + std::format("Invalid safety_level value: {}", safetyLevel)); } } @@ -1314,7 +1306,8 @@ setupDatabaseCon(Config const& c, std::optional j) } else { - Throw("Invalid journal_mode value: " + journalMode); + Throw( + std::format("Invalid journal_mode value: {}", journalMode)); } } @@ -1335,7 +1328,8 @@ setupDatabaseCon(Config const& c, std::optional j) } else { - Throw("Invalid synchronous value: " + synchronous); + Throw( + std::format("Invalid synchronous value: {}", synchronous)); } } @@ -1356,7 +1350,7 @@ setupDatabaseCon(Config const& c, std::optional j) } else { - Throw("Invalid temp_store value: " + tempStore); + Throw(std::format("Invalid temp_store value: {}", tempStore)); } } diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index 1c1ce67455..199e126e1a 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -1661,8 +1662,8 @@ setupOverlay(BasicConfig const& config, beast::Journal j) } catch (boost::bad_lexical_cast const&) { - Throw( - "Configured [crawl] section has invalid value: " + values.front()); + Throw(std::format( + "Configured [crawl] section has invalid value: {}", values.front())); } }