Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Util::BacktraceException wrapper #225

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Bitcoin/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ Tx::Tx(std::string const& s) {
auto is = std::istringstream(std::move(str));
is >> *this;
if (!is.good())
throw std::invalid_argument("Bitcoin::Tx: invalid hex string input.");
throw Util::BacktraceException<std::invalid_argument>("Bitcoin::Tx: invalid hex string input.");
if (is.get() != std::char_traits<char>::eof())
throw std::invalid_argument("Bitcoin::Tx: input string too long.");
throw Util::BacktraceException<std::invalid_argument>("Bitcoin::Tx: input string too long.");
}

Bitcoin::TxId Tx::get_txid() const {
Expand Down
5 changes: 3 additions & 2 deletions Bitcoin/addr_to_scriptPubKey.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#ifndef BITCOIN_ADDR_TO_SCRIPTPUBKEY_HPP
#define BITCOIN_ADDR_TO_SCRIPTPUBKEY_HPP

#include"Util/BacktraceException.hpp"
#include<cstdint>
#include<string>
#include<stdexcept>
#include<vector>

namespace Bitcoin {

struct UnknownAddrType : public std::invalid_argument {
struct UnknownAddrType : public Util::BacktraceException<std::invalid_argument> {
public:
UnknownAddrType()
: std::invalid_argument("Bitcoin::UnknownAddrType") { }
: Util::BacktraceException<std::invalid_argument>("Bitcoin::UnknownAddrType") { }
};

/** Bitcoin::addr_to_scriptPubKey
Expand Down
4 changes: 2 additions & 2 deletions Bitcoin/sighash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ enum SighashFlags
, SIGHASH_ANYONECANPAY = 0x80
};

struct InvalidSighash : public std::invalid_argument {
struct InvalidSighash : public Util::BacktraceException<std::invalid_argument> {
InvalidSighash() =delete;
InvalidSighash(std::string const& msg)
: std::invalid_argument(
: Util::BacktraceException<std::invalid_argument>(
std::string("Bitcoin::InvalidSighash: ") + msg
) { }
};
Expand Down
5 changes: 3 additions & 2 deletions Boltz/ConnectionIF.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BOLTZ_CONNECTIONIF_HPP
#define BOLTZ_CONNECTIONIF_HPP

#include"Util/BacktraceException.hpp"
#include<memory>
#include<stdexcept>
#include<string>
Expand Down Expand Up @@ -35,10 +36,10 @@ class ConnectionIF {
* @brief thrown when communications with
* the BOLTZ server has problems.
*/
class ApiError : public std::runtime_error {
class ApiError : public Util::BacktraceException<std::runtime_error> {
public:
ApiError(std::string const& e
) : std::runtime_error(e) { }
) : Util::BacktraceException<std::runtime_error>(e) { }
};

}
Expand Down
10 changes: 6 additions & 4 deletions Boss/Mod/ChannelCreateDestroyMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ void ChannelCreateDestroyMonitor::start() {
try {
auto payload = params["channel_opened"];
n = Ln::NodeId(std::string(payload["id"]));
} catch (std::runtime_error const&) {
} catch (std::runtime_error const& err) {
return Boss::log( bus, Error
, "ChannelCreateDestroyMonitor: "
"Unexpected channel_opened "
"payload: %s"
"payload: %s: %s"
, Util::stringify(params).c_str()
, err.what()
);
}
/* Is it already in channeled? */
Expand All @@ -174,12 +175,13 @@ void ChannelCreateDestroyMonitor::start() {
n = Ln::NodeId(std::string(payload["peer_id"]));
old_state = std::string(payload["old_state"]);
new_state = std::string(payload["new_state"]);
} catch (std::runtime_error const&) {
} catch (std::runtime_error const& err) {
return Boss::log( bus, Error
, "ChannelCreateDestroyMonitor: "
"Unexpected channel_state_changed "
"payload: %s"
"payload: %s: %s"
, Util::stringify(params).c_str()
, err.what()
);
}
/* Only continue if we are leaving the CHANNELD_NORMAL
Expand Down
5 changes: 3 additions & 2 deletions Boss/Mod/ChannelCreator/Carpenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ Carpenter::construct(std::map<Ln::NodeId, Ln::Amount> plan) {
report << ", ";
report << node;
}
} catch (std::invalid_argument const&) {
} catch (std::invalid_argument const& ex) {
auto os = std::ostringstream();
os << res;
return Boss::log( bus, Error
, "ChannelCreator::Carpenter: "
"Unexpected result from "
"multifundchannel: %s"
"multifundchannel: %s: %s"
, os.str().c_str()
, ex.what()
);
}

Expand Down
5 changes: 3 additions & 2 deletions Boss/Mod/ChannelFinderByEarnedFee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,13 @@ class ChannelFinderByEarnedFee::Impl {
continue;
props.emplace(std::move(dest));
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "ChannelFinderByEarnedFees: "
"Unexpected result from "
"`listchannels`: %s"
"`listchannels`: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
);
}
res = Jsmn::Object();
Expand Down
5 changes: 3 additions & 2 deletions Boss/Mod/ChannelFinderByListpays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ Ev::Io<void> ChannelFinderByListpays::extract_payees_loop() {
++pit->second;
++count;
return extract_payees_loop();
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "ChannelFinderByListpays: "
"Unexpected result from `listpays` "
"`pays` field: %s"
"`pays` field: %s: %s"
, Util::stringify(pay).c_str()
, ex.what()
);
}
});
Expand Down
8 changes: 4 additions & 4 deletions Boss/Mod/FeeModderByBalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ class FeeModderByBalance::Impl {
);
break;
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
found = false;
act = Boss::log( bus, Error
, "FeeModderByBalance: "
"Unexpected result from "
"listpeerchannels: %s"
, Util::stringify(res)
.c_str()
"listpeerchannels: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
);
}
typedef ChannelSpecs CS;
Expand Down
8 changes: 4 additions & 4 deletions Boss/Mod/FeeModderBySize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ class FeeModderBySize::Impl {
continue;
rv.insert(n);
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "FeeModderBySize: "
"get_competitors: "
"Unexpected result from "
"listchannels: %s"
, Util::stringify(res)
.c_str()
"listchannels: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
).then([rv]() {
return Ev::lift(rv);
});
Expand Down
5 changes: 3 additions & 2 deletions Boss/Mod/ForwardFeeMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ void ForwardFeeMonitor::start() {
- double(payload["received_time"])
;

} catch (std::runtime_error const& _) {
} catch (std::runtime_error const& err) {
return Boss::log( bus, Error
, "ForwardFeeMonitor: Unexpected "
"forward_event payload: %s"
"forward_event payload: %s: %s"
, Util::stringify(n.params).c_str()
, err.what()
);
}

Expand Down
8 changes: 4 additions & 4 deletions Boss/Mod/FundsMover/Attempter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,15 @@ class Attempter::Impl : public std::enable_shared_from_this<Impl> {
data["failcode"]
));
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return std::move(act)
+ Boss::log( bus, Error
, "FundsMover: Attempt: "
"Unexpected error from "
"%s: %s"
"%s: %s: %s"
, e.command.c_str()
, Util::stringify(e.error)
.c_str()
, Util::stringify(e.error).c_str()
, ex.what()
);
}

Expand Down
10 changes: 6 additions & 4 deletions Boss/Mod/FundsMover/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ Ev::Io<void> Runner::gather_info() {
));
break;
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "FundsMover: Unexpected result "
"from listchannels: %s"
"from listchannels: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
);
}
return Ev::lift();
Expand Down Expand Up @@ -134,11 +135,12 @@ Ev::Io<void> Runner::gather_info() {
));
break;
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "FundsMover: Unexpected result "
"from listchannels: %s"
"from listchannels: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
);
}
return Ev::lift();
Expand Down
2 changes: 1 addition & 1 deletion Boss/Mod/Initiator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Initiator::Impl {
, meth
, is.c_str()
).then([]() {
throw std::runtime_error("Unexpected result.");
throw Util::BacktraceException<std::runtime_error>("Unexpected result.");
return Ev::lift();
});
}
Expand Down
5 changes: 3 additions & 2 deletions Boss/Mod/JitRebalancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,12 @@ class JitRebalancer::Impl::Run::Impl {
av.to_us += to_us;
av.capacity += capacity;
}
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "JitRebalancer: Unexpected "
"result from listpeerchannels: %s"
"result from listpeerchannels: %s: %s"
, Util::stringify(res).c_str()
, ex.what()
).then([]() {
throw Continue();
return Ev::lift();
Expand Down
14 changes: 7 additions & 7 deletions Boss/Mod/PaymentDeleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class PaymentDeleter::Impl {
try {
pays = res["pays"];
it = pays.begin();
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "PaymentDeleter: Unexpected "
"result from 'listpays': "
"%s"
"result from 'listpays': %s: %s"
, Util::stringify(res).c_str()
, ex.what()
);
}
return loop();
Expand Down Expand Up @@ -156,13 +156,13 @@ class PaymentDeleter::Impl {
+ delpay(payment_hash, status)
+ loop()
;
} catch (std::exception const&) {
} catch (std::exception const& ex) {
return Boss::log( bus, Error
, "PaymentDeleter: "
"Unexpected 'pays' entry "
"from 'listpays': %s"
, Util::stringify(pay)
.c_str()
"from 'listpays': %s: %s"
, Util::stringify(pay).c_str()
, ex.what()
);
}
});
Expand Down
8 changes: 4 additions & 4 deletions Boss/Mod/PeerJudge/DataGatherer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ class DataGatherer::Impl {
id, total
});
}
} catch (std::exception const& e) {
} catch (std::exception const& ex) {
infos->clear();
return Boss::log( bus, Error
, "PeerJudge: Unexpected "
"listpeers result: %s"
, Util::stringify(peers)
.c_str()
"listpeers result: %s: %s"
, Util::stringify(peers).c_str()
, ex.what()
);
}
return Ev::lift();
Expand Down
8 changes: 4 additions & 4 deletions Boss/Mod/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string RpcError::make_error_message( std::string const& command

RpcError::RpcError( std::string command_
, Jsmn::Object error_
) : std::runtime_error(make_error_message(command_, error_))
) : Util::BacktraceException<std::runtime_error>(make_error_message(command_, error_))
, command(command_)
, error(error_)
{ }
Expand Down Expand Up @@ -200,13 +200,13 @@ class Rpc::Impl {
return std::size_t(0);
}
if (res < 0)
throw std::runtime_error(
throw Util::BacktraceException<std::runtime_error>(
std::string("Rpc: read: ") +
strerror(errno)
);
if (res == 0)
/* Unexpected end of file! */
throw std::runtime_error(
throw Util::BacktraceException<std::runtime_error>(
"Rpc: read: unexpected end-of-file "
"in RPC socket."
);
Expand Down Expand Up @@ -263,7 +263,7 @@ class Rpc::Impl {
))
break;
if (res < 0)
throw std::runtime_error(
throw Util::BacktraceException<std::runtime_error>(
std::string("Rpc: write: ") +
strerror(errno)
);
Expand Down
2 changes: 1 addition & 1 deletion Boss/Mod/Rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace S { class Bus; }

namespace Boss { namespace Mod {

struct RpcError : public std::runtime_error {
struct RpcError : public Util::BacktraceException<std::runtime_error> {
private:
static
std::string make_error_message( std::string const&
Expand Down
2 changes: 1 addition & 1 deletion Boss/Mod/UnmanagedManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class UnmanagedManager::Impl {
for (auto const& tag : tags) {
auto it = tag_informs.find(tag);
if (it == tag_informs.end())
throw std::runtime_error(
throw Util::BacktraceException<std::runtime_error>(
std::string("Unknown tag: ") + tag
);
}
Expand Down
Loading
Loading