Skip to content

Commit

Permalink
Add logging for exceptions (#3213)
Browse files Browse the repository at this point in the history
  • Loading branch information
drlongle committed Mar 29, 2023
1 parent 46167d1 commit 8e1d824
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 52 deletions.
12 changes: 7 additions & 5 deletions src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,11 @@ RCLConsensus::Adaptor::doAccept(
std::make_shared<STTx const>(SerialIter{item.slice()}));
JLOG(j_.debug()) << " Tx: " << item.key();
}
catch (std::exception const&)
catch (std::exception const& ex)
{
failed.insert(item.key());
JLOG(j_.warn()) << " Tx: " << item.key() << " throws!";
JLOG(j_.warn())
<< " Tx: " << item.key() << " throws: " << ex.what();
}
}

Expand Down Expand Up @@ -615,10 +616,11 @@ RCLConsensus::Adaptor::doAccept(

anyDisputes = true;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j_.debug())
<< "Failed to apply transaction we voted NO on";
JLOG(j_.debug()) << "Failed to apply transaction we voted "
"NO on. Exception: "
<< ex.what();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/app/ledger/ConsensusTransSetSF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ ConsensusTransSetSF::gotNode(
pap->getOPs().submitTransaction(stx);
});
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j_.warn()) << "Fetched invalid transaction in proposed set";
JLOG(j_.warn())
<< "Fetched invalid transaction in proposed set. Exception: "
<< ex.what();
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Ledger::Ledger(
, txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
, stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
, rules_{config.features}
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = 1;
info_.drops = INITIAL_XRP;
Expand Down Expand Up @@ -255,6 +256,7 @@ Ledger::Ledger(
std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
, rules_(config.features)
, info_(info)
, j_(j)
{
loaded = true;

Expand Down Expand Up @@ -306,6 +308,7 @@ Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
, stateMap_(prevLedger.stateMap_->snapShot(true))
, fees_(prevLedger.fees_)
, rules_(prevLedger.rules_)
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = prevLedger.info_.seq + 1;
info_.parentCloseTime = prevLedger.info_.closeTime;
Expand Down Expand Up @@ -339,6 +342,7 @@ Ledger::Ledger(LedgerInfo const& info, Config const& config, Family& family)
std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
, rules_{config.features}
, info_(info)
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.hash = calculateLedgerHash(info_);
}
Expand All @@ -352,6 +356,7 @@ Ledger::Ledger(
, txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
, stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
, rules_{config.features}
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = ledgerSeq;
info_.closeTime = closeTime;
Expand Down Expand Up @@ -626,8 +631,9 @@ Ledger::setup()
{
ret = false;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
Rethrow();
}

Expand Down Expand Up @@ -682,8 +688,9 @@ Ledger::setup()
{
ret = false;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
Rethrow();
}

Expand Down
1 change: 1 addition & 0 deletions src/ripple/app/ledger/Ledger.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class Ledger final : public std::enable_shared_from_this<Ledger>,
Fees fees_;
Rules rules_;
LedgerInfo info_;
beast::Journal j_;
};

/** A ledger wrapped in a CachedView. */
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/app/ledger/impl/BuildLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ applyTransactions(
++it;
}
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j.warn()) << "Transaction " << txid << " throws";
JLOG(j.warn())
<< "Transaction " << txid << " throws: " << ex.what();
failed.insert(txid);
it = txns.erase(it);
}
Expand Down
20 changes: 12 additions & 8 deletions src/ripple/app/ledger/impl/LedgerMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,10 +866,11 @@ LedgerMaster::fixMismatch(ReadView const& ledger)
{
hash = hashOfSeq(ledger, lSeq, m_journal);
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(m_journal.warn())
<< "fixMismatch encounters partial ledger";
<< "fixMismatch encounters partial ledger. Exception: "
<< ex.what();
clearLedger(lSeq);
return;
}
Expand Down Expand Up @@ -1407,10 +1408,11 @@ LedgerMaster::findNewLedgersToPublish(
JLOG(m_journal.trace())
<< "ready to publish " << ret.size() << " ledgers.";
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(m_journal.error())
<< "Exception while trying to find ledgers to publish.";
<< "Exception while trying to find ledgers to publish: "
<< ex.what();
}

if (app_.config().LEDGER_REPLAY)
Expand Down Expand Up @@ -2009,9 +2011,10 @@ LedgerMaster::fetchForHistory(
}
}
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(m_journal.warn()) << "Threw while prefetching";
JLOG(m_journal.warn())
<< "Threw while prefetching: " << ex.what();
}
}
}
Expand Down Expand Up @@ -2346,9 +2349,10 @@ LedgerMaster::makeFetchPack(

peer->send(msg);
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(m_journal.warn()) << "Exception building fetch pach";
JLOG(m_journal.warn())
<< "Exception building fetch pach. Exception: " << ex.what();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/ripple/app/ledger/impl/LedgerToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ fillJsonTx(Object& json, LedgerFill const& fill)
appendAll(fill.ledger.txs);
}
}
catch (std::exception const&)
catch (std::exception const& ex)
{
// Nothing the user can do about this.
if (fill.context)
{
JLOG(fill.context->j.error())
<< "Exception in " << __func__ << ": " << ex.what();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/ledger/impl/OpenLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ debugTostr(SHAMap const& set)
auto const tx = std::make_shared<STTx const>(sit);
ss << debugTxstr(tx) << ", ";
}
catch (std::exception const&)
catch (std::exception const& ex)
{
ss << "THRO, ";
ss << "THROW:" << ex.what() << ", ";
}
}
return ss.str();
Expand Down
18 changes: 12 additions & 6 deletions src/ripple/app/misc/Manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,26 @@ to_string(Manifest const& m);
*/
/** @{ */
std::optional<Manifest>
deserializeManifest(Slice s);
deserializeManifest(Slice s, beast::Journal journal);

inline std::optional<Manifest>
deserializeManifest(std::string const& s)
deserializeManifest(
std::string const& s,
beast::Journal journal = beast::Journal(beast::Journal::getNullSink()))
{
return deserializeManifest(makeSlice(s));
return deserializeManifest(makeSlice(s), journal);
}

template <
class T,
class = std::enable_if_t<
std::is_same<T, char>::value || std::is_same<T, unsigned char>::value>>
std::optional<Manifest>
deserializeManifest(std::vector<T> const& v)
deserializeManifest(
std::vector<T> const& v,
beast::Journal journal = beast::Journal(beast::Journal::getNullSink()))
{
return deserializeManifest(makeSlice(v));
return deserializeManifest(makeSlice(v), journal);
}
/** @} */

Expand All @@ -180,7 +184,9 @@ struct ValidatorToken
};

std::optional<ValidatorToken>
loadValidatorToken(std::vector<std::string> const& blob);
loadValidatorToken(
std::vector<std::string> const& blob,
beast::Journal journal = beast::Journal(beast::Journal::getNullSink()));

enum class ManifestDisposition {
/// Manifest is valid
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,10 @@ NetworkOPsImp::submitTransaction(std::shared_ptr<STTx const> const& iTrans)
return;
}
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(m_journal.warn()) << "Exception checking transaction" << txid;
JLOG(m_journal.warn())
<< "Exception checking transaction " << txid << ": " << ex.what();

return;
}
Expand Down
12 changes: 8 additions & 4 deletions src/ripple/app/misc/impl/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ to_string(Manifest const& m)
}

std::optional<Manifest>
deserializeManifest(Slice s)
deserializeManifest(Slice s, beast::Journal journal)
{
if (s.empty())
return std::nullopt;
Expand Down Expand Up @@ -148,8 +148,10 @@ deserializeManifest(Slice s)

return m;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(journal.error())
<< "Exception in " << __func__ << ": " << ex.what();
return std::nullopt;
}
}
Expand Down Expand Up @@ -239,7 +241,7 @@ Manifest::getMasterSignature() const
}

std::optional<ValidatorToken>
loadValidatorToken(std::vector<std::string> const& blob)
loadValidatorToken(std::vector<std::string> const& blob, beast::Journal journal)
{
try
{
Expand Down Expand Up @@ -277,8 +279,10 @@ loadValidatorToken(std::vector<std::string> const& blob)

return std::nullopt;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(journal.error())
<< "Exception in " << __func__ << ": " << ex.what();
return std::nullopt;
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/ripple/app/misc/impl/ValidatorSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,9 @@ ValidatorSite::onTimer(std::size_t siteIdx, error_code const& ec)
// the WorkSSL client ctor can throw if SSL init fails
makeRequest(sites_[siteIdx].startingResource, siteIdx, lock);
}
catch (std::exception&)
catch (std::exception const& ex)
{
JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
onSiteFetch(
boost::system::error_code{-1, boost::system::generic_category()},
{},
Expand Down Expand Up @@ -526,7 +527,7 @@ ValidatorSite::processRedirect(
throw std::runtime_error(
"invalid scheme in redirect " + newLocation->pUrl.scheme);
}
catch (std::exception&)
catch (std::exception const& ex)
{
JLOG(j_.error()) << "Invalid redirect location: "
<< res[field::location];
Expand Down Expand Up @@ -606,8 +607,10 @@ ValidatorSite::onSiteFetch(
}
}
}
catch (std::exception& ex)
catch (std::exception const& ex)
{
JLOG(j_.error())
<< "Exception in " << __func__ << ": " << ex.what();
onError(ex.what(), false);
}
}
Expand Down Expand Up @@ -643,8 +646,10 @@ ValidatorSite::onTextFetch(

parseJsonResponse(res, siteIdx, lock_sites);
}
catch (std::exception& ex)
catch (std::exception const& ex)
{
JLOG(j_.error())
<< "Exception in " << __func__ << ": " << ex.what();
sites_[siteIdx].lastRefreshStatus.emplace(Site::Status{
clock_type::now(), ListDisposition::invalid, ex.what()});
}
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/tx/impl/apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ applyTransaction(
JLOG(j.debug()) << "Transaction retry: " << transHuman(result.first);
return ApplyResult::Retry;
}
catch (std::exception const&)
catch (std::exception const& ex)
{
JLOG(j.warn()) << "Throws";
JLOG(j.warn()) << "Throws: " << ex.what();
return ApplyResult::Fail;
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/ripple/basics/impl/make_SSLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,13 @@ initAuthenticated(

fclose(f);
}
catch (std::exception const&)
catch (std::exception const& ex)
{
fclose(f);
LogicError("Reading the SSL chain file generated an exception.");
LogicError(
std::string(
"Reading the SSL chain file generated an exception: ") +
ex.what());
}
}

Expand Down
Loading

0 comments on commit 8e1d824

Please sign in to comment.