diff --git a/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp b/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp index 2cb1c890b8..2a87baa29f 100644 --- a/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp +++ b/cameraserver/multiCameraServer/src/main/native/cpp/main.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -63,10 +64,6 @@ struct CameraConfig { std::vector cameras; -wpi::raw_ostream& ParseError() { - return wpi::errs() << "config error in '" << configFile << "': "; -} - bool ReadCameraConfig(const wpi::json& config) { CameraConfig c; @@ -74,7 +71,8 @@ bool ReadCameraConfig(const wpi::json& config) { try { c.name = config.at("name").get(); } catch (const wpi::json::exception& e) { - ParseError() << "could not read camera name: " << e.what() << '\n'; + fmt::print(stderr, "config error in '{}': could not read camera name: {}\n", + configFile, e.what()); return false; } @@ -82,8 +80,9 @@ bool ReadCameraConfig(const wpi::json& config) { try { c.path = config.at("path").get(); } catch (const wpi::json::exception& e) { - ParseError() << "camera '" << c.name - << "': could not read path: " << e.what() << '\n'; + fmt::print(stderr, + "config error in '{}': camera '{}': could not read path: {}\n", + configFile, c.name, e.what()); return false; } @@ -98,8 +97,7 @@ bool ReadConfig() { std::error_code ec; wpi::raw_fd_istream is(configFile, ec); if (ec) { - wpi::errs() << "could not open '" << configFile << "': " << ec.message() - << '\n'; + fmt::print(stderr, "could not open '{}': {}\n", configFile, ec.message()); return false; } @@ -108,13 +106,15 @@ bool ReadConfig() { try { j = wpi::json::parse(is); } catch (const wpi::json::parse_error& e) { - fmt::print(ParseError(), "byte {}: {}\n", e.byte, e.what()); + fmt::print(stderr, "config error in '{}': byte {}: {}\n", configFile, + e.byte, e.what()); return false; } // top level must be an object if (!j.is_object()) { - ParseError() << "must be JSON object\n"; + fmt::print(stderr, "config error in '{}': must be JSON object\n", + configFile); return false; } @@ -122,7 +122,8 @@ bool ReadConfig() { try { team = j.at("team").get(); } catch (const wpi::json::exception& e) { - ParseError() << "could not read team number: " << e.what() << '\n'; + fmt::print(stderr, "config error in '{}': could not read team number: {}\n", + configFile, e.what()); return false; } @@ -135,10 +136,14 @@ bool ReadConfig() { } else if (wpi::equals_lower(str, "server")) { server = true; } else { - ParseError() << "could not understand ntmode value '" << str << "'\n"; + fmt::print( + stderr, + "config error in '{}': could not understand ntmode value '{}'\n", + configFile, str); } } catch (const wpi::json::exception& e) { - ParseError() << "could not read ntmode: " << e.what() << '\n'; + fmt::print(stderr, "config error in '{}': could not read ntmode: {}\n", + configFile, e.what()); } } @@ -150,7 +155,8 @@ bool ReadConfig() { } } } catch (const wpi::json::exception& e) { - ParseError() << "could not read cameras: " << e.what() << '\n'; + fmt::print(stderr, "config error in '{}': could not read cameras: {}\n", + configFile, e.what()); return false; } diff --git a/wpiutil/src/main/native/include/wpi/jni_util.h b/wpiutil/src/main/native/include/wpi/jni_util.h index bc4488a795..31bdf93ed8 100644 --- a/wpiutil/src/main/native/include/wpi/jni_util.h +++ b/wpiutil/src/main/native/include/wpi/jni_util.h @@ -15,6 +15,8 @@ #include #include +#include + #include "wpi/ConvertUTF.h" #include "wpi/SafeThread.h" #include "wpi/SmallString.h" @@ -158,8 +160,8 @@ class JStringRef { env->ReleaseStringCritical(str, chars); } } else { - errs() << "JStringRef was passed a null pointer at \n" - << GetJavaStackTrace(env); + fmt::print(stderr, "JStringRef was passed a null pointer at\n", + GetJavaStackTrace(env)); } // Ensure str is null-terminated. m_str.push_back('\0'); @@ -281,8 +283,8 @@ class JSpanBase { m_elements{static_cast*>( bb ? env->GetDirectBufferAddress(bb) : nullptr)} { if (!bb) { - errs() << "JSpan was passed a null pointer at \n" - << GetJavaStackTrace(env); + fmt::print(stderr, "JSpan was passed a null pointer at\n", + GetJavaStackTrace(env)); } } @@ -300,8 +302,8 @@ class JSpanBase { m_elements = ArrHelper::GetArrayElements(env, jarr); } } else { - errs() << "JSpan was passed a null pointer at \n" - << GetJavaStackTrace(env); + fmt::print(stderr, "JSpan was passed a null pointer at\n", + GetJavaStackTrace(env)); } }