Skip to content

Commit b5f079e

Browse files
committed
[futurepress#96] Windows: Improves native error messages (includes server ID into them)
1 parent 018e4d9 commit b5f079e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

windows/ReactNativeStaticServer/ReactNativeModule.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ void OnSignal(std::string signal, std::string details) {
4040
// thus MUST BE called before the object is dropped below, if it is.
4141
if (!pendingResult) mod->sendEvent(signal, details);
4242

43+
double id = server->id();
4344
if (signal == CRASHED || signal == TERMINATED) {
4445
delete server;
4546
server = NULL;
4647
}
4748

4849
if (pendingResult) {
49-
if (signal == CRASHED) RNException("Server crashed").reject(*pendingResult);
50+
if (signal == CRASHED) {
51+
RNException("Server #" + std::to_string(id) + " crashed").reject(*pendingResult);
52+
}
5053
else pendingResult->Resolve(details);
5154
delete pendingResult;
5255
pendingResult = NULL;
@@ -138,7 +141,9 @@ void ReactNativeModule::start(
138141
lock_sem();
139142

140143
if (server) {
141-
RNException("Another server instance is active").reject(result);
144+
RNException(
145+
"Failed to launch server #" + std::to_string(id) +
146+
", another server instance (#" + server->id_str() + ") is active").reject(result);
142147
unlock_sem();
143148
return;
144149
};
@@ -187,6 +192,6 @@ void ReactNativeModule::stop(React::ReactPromise<std::string>&& result) noexcept
187192
// will catch it and report to JS layer in RN way.
188193
}
189194
catch (...) {
190-
RNException("Failed to gracefully shutdown the server").reject(result);
195+
RNException("Failed to gracefully shutdown the server #" + server->id_str()).reject(result);
191196
}
192197
}

windows/ReactNativeStaticServer/Server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace winrt::ReactNativeStaticServer {
1919
SignalConsumer signalConsumer);
2020

2121
inline double id() { return _id; }
22+
inline std::string id_str() { return std::to_string(_id); }
2223

2324
void launch();
2425
void shutdown();

0 commit comments

Comments
 (0)