From b5f079eec9252b6fa94569e8868d1f1f26e4bf01 Mon Sep 17 00:00:00 2001 From: "Dr. Sergey Pogodin" Date: Mon, 26 Feb 2024 12:54:14 +0100 Subject: [PATCH] [#96] Windows: Improves native error messages (includes server ID into them) --- windows/ReactNativeStaticServer/ReactNativeModule.cpp | 11 ++++++++--- windows/ReactNativeStaticServer/Server.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/windows/ReactNativeStaticServer/ReactNativeModule.cpp b/windows/ReactNativeStaticServer/ReactNativeModule.cpp index d2b2d1e6..a683a183 100644 --- a/windows/ReactNativeStaticServer/ReactNativeModule.cpp +++ b/windows/ReactNativeStaticServer/ReactNativeModule.cpp @@ -40,13 +40,16 @@ void OnSignal(std::string signal, std::string details) { // thus MUST BE called before the object is dropped below, if it is. if (!pendingResult) mod->sendEvent(signal, details); + double id = server->id(); if (signal == CRASHED || signal == TERMINATED) { delete server; server = NULL; } if (pendingResult) { - if (signal == CRASHED) RNException("Server crashed").reject(*pendingResult); + if (signal == CRASHED) { + RNException("Server #" + std::to_string(id) + " crashed").reject(*pendingResult); + } else pendingResult->Resolve(details); delete pendingResult; pendingResult = NULL; @@ -138,7 +141,9 @@ void ReactNativeModule::start( lock_sem(); if (server) { - RNException("Another server instance is active").reject(result); + RNException( + "Failed to launch server #" + std::to_string(id) + + ", another server instance (#" + server->id_str() + ") is active").reject(result); unlock_sem(); return; }; @@ -187,6 +192,6 @@ void ReactNativeModule::stop(React::ReactPromise&& result) noexcept // will catch it and report to JS layer in RN way. } catch (...) { - RNException("Failed to gracefully shutdown the server").reject(result); + RNException("Failed to gracefully shutdown the server #" + server->id_str()).reject(result); } } diff --git a/windows/ReactNativeStaticServer/Server.h b/windows/ReactNativeStaticServer/Server.h index 4c3d5e50..06f643e7 100644 --- a/windows/ReactNativeStaticServer/Server.h +++ b/windows/ReactNativeStaticServer/Server.h @@ -19,6 +19,7 @@ namespace winrt::ReactNativeStaticServer { SignalConsumer signalConsumer); inline double id() { return _id; } + inline std::string id_str() { return std::to_string(_id); } void launch(); void shutdown();