mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch std::print() to not throw when we ultimately migrate to it. fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
This commit is contained in:
@@ -6,10 +6,10 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/SmallString.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpinet/uv/util.h>
|
||||
|
||||
#include "HALSimWSClientConnection.h"
|
||||
@@ -26,7 +26,7 @@ HALSimWS::HALSimWS(wpi::uv::Loop& loop, ProviderContainer& providers,
|
||||
m_providers(providers),
|
||||
m_simDevicesProvider(simDevicesProvider) {
|
||||
m_loop.error.connect([](uv::Error err) {
|
||||
fmt::print(stderr, "HALSim WS Client libuv Error: {}\n", err.str());
|
||||
wpi::print(stderr, "HALSim WS Client libuv Error: {}\n", err.str());
|
||||
});
|
||||
|
||||
m_tcp_client = uv::Tcp::Create(m_loop);
|
||||
@@ -54,7 +54,7 @@ bool HALSimWS::Initialize() {
|
||||
try {
|
||||
m_port = std::stoi(port);
|
||||
} catch (const std::invalid_argument& err) {
|
||||
fmt::print(stderr, "Error decoding HALSIMWS_PORT ({})\n", err.what());
|
||||
wpi::print(stderr, "Error decoding HALSIMWS_PORT ({})\n", err.what());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -109,16 +109,16 @@ void HALSimWS::Start() {
|
||||
|
||||
// Print any filters we are using
|
||||
if (m_useMsgFiltering) {
|
||||
fmt::print("WS Message Filters:");
|
||||
wpi::print("WS Message Filters:");
|
||||
for (auto filter : m_msgFilters.keys()) {
|
||||
fmt::print("* \"{}\"\n", filter);
|
||||
wpi::print("* \"{}\"\n", filter);
|
||||
}
|
||||
} else {
|
||||
fmt::print("No WS Message Filters specified");
|
||||
wpi::print("No WS Message Filters specified");
|
||||
}
|
||||
|
||||
// Set up the connection timer
|
||||
fmt::print("Will attempt to connect to ws://{}:{}{}\n", m_host, m_port,
|
||||
wpi::print("Will attempt to connect to ws://{}:{}{}\n", m_host, m_port,
|
||||
m_uri);
|
||||
|
||||
// Set up the timer to attempt connection
|
||||
@@ -132,7 +132,7 @@ void HALSimWS::Start() {
|
||||
void HALSimWS::AttemptConnect() {
|
||||
m_connect_attempts++;
|
||||
|
||||
fmt::print("Connection Attempt {}\n", m_connect_attempts);
|
||||
wpi::print("Connection Attempt {}\n", m_connect_attempts);
|
||||
|
||||
struct sockaddr_in dest;
|
||||
uv::NameToAddr(m_host, m_port, &dest);
|
||||
@@ -197,7 +197,7 @@ void HALSimWS::OnNetValueChanged(const wpi::json& msg) {
|
||||
provider->OnNetValueChanged(msg.at("data"));
|
||||
}
|
||||
} catch (wpi::json::exception& e) {
|
||||
fmt::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
wpi::print(stderr, "Error with incoming message: {}\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpinet/raw_uv_ostream.h>
|
||||
|
||||
#include "HALSimWS.h"
|
||||
@@ -52,7 +52,7 @@ void HALSimWSClientConnection::Initialize() {
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
std::string err("JSON parse failed: ");
|
||||
err += e.what();
|
||||
fmt::print(stderr, "{}\n", err);
|
||||
wpi::print(stderr, "{}\n", err);
|
||||
m_websocket->Fail(1003, err);
|
||||
return;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ void HALSimWSClientConnection::OnSimValueChanged(const wpi::json& msg) {
|
||||
return;
|
||||
}
|
||||
} catch (wpi::json::exception& e) {
|
||||
fmt::print(stderr, "Error with message: {}\n", e.what());
|
||||
wpi::print(stderr, "Error with message: {}\n", e.what());
|
||||
}
|
||||
|
||||
wpi::SmallVector<uv::Buffer, 4> sendBufs;
|
||||
@@ -103,7 +103,7 @@ void HALSimWSClientConnection::OnSimValueChanged(const wpi::json& msg) {
|
||||
}
|
||||
|
||||
if (err) {
|
||||
fmt::print(stderr, "{}\n", err.str());
|
||||
wpi::print(stderr, "{}\n", err.str());
|
||||
std::fflush(stderr);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user