fix: Detect and log ccapi depth msg parse errors

This fixes a crash that would happen if a depth item's price or quantity
were an empty string (now we log an error and keep going).
This commit is contained in:
John Colvin committed 2024-09-13 10:50:20 -04:00
1 parent be4895faa6
commit dec1061b40
1 file changed
+15 -2
@@ -9,6 +9,7 @@
#include <ccapi_cpp/ccapi_macro.h>
#include <ccapi_cpp/ccapi_message.h>
#include <ccapi_cpp/ccapi_session.h>
#include <exception>
#include <vector>
namespace bts::md {
@@ -32,8 +33,20 @@ static bool parse(const ccapi::Message &msg, domain::Book &book) {
// ["ASK_PRICE", "ASK_SIZE"]
const auto &props = level.getNameValueMap();
for (const auto &[name, value] : props) {
bid_walker.parse_field(name, value) ||
ask_walker.parse_field(name, value);
if (value.empty()) {
LOG(md, Error,
"Received depth item with empty '{}' value. full_msg:\n{}",
name, msg.toStringPretty());
continue;
}
try {
bid_walker.parse_field(name, value) ||
ask_walker.parse_field(name, value);
} catch (const std::exception &ex) {
LOG(md, Fatal, "Error parsing depth update: {}\nmsg:\n{}",
std::string{ex.what()}, msg.toStringPretty());
bts_assert_msg(false, "Fatal error parsing depth update.");
}
}
}