Skip to content

Commit

Permalink
[futurepress#96] Windows: Improves native error messages (includes se…
Browse files Browse the repository at this point in the history
…rver ID into them)
  • Loading branch information
birdofpreyru committed Feb 26, 2024
1 parent 018e4d9 commit b5f079e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions windows/ReactNativeStaticServer/ReactNativeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -187,6 +192,6 @@ void ReactNativeModule::stop(React::ReactPromise<std::string>&& 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);
}
}
1 change: 1 addition & 0 deletions windows/ReactNativeStaticServer/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b5f079e

Please sign in to comment.