Skip to content

Commit

Permalink
wrap the remaining handlers in try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktrn committed Oct 16, 2024
1 parent aad66a2 commit 9bba3cf
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions apps/coordinator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,11 @@ class TaskCoordinator {
socket.on("TEST", (message, callback) => {
logger.log("Handling TEST", { eventName: "TEST", ...getSocketMetadata(), ...message });

callback();
try {
callback();
} catch (error) {
logger.error("TEST error", { error });
}
});

// Deprecated: Only workers without support for lazy attempts use this
Expand Down Expand Up @@ -1275,7 +1279,11 @@ class TaskCoordinator {

log.log("Handling UNRECOVERABLE_ERROR");

await crashRun(message.error);
try {
await crashRun(message.error);
} catch (error) {
log.error("UNRECOVERABLE_ERROR error", { error });
}
});

socket.on("SET_STATE", async (message) => {
Expand All @@ -1287,20 +1295,28 @@ class TaskCoordinator {

log.log("Handling SET_STATE");

if (message.attemptFriendlyId) {
updateAttemptFriendlyId(message.attemptFriendlyId);
}
try {
if (message.attemptFriendlyId) {
updateAttemptFriendlyId(message.attemptFriendlyId);
}

if (message.attemptNumber) {
updateAttemptNumber(message.attemptNumber);
if (message.attemptNumber) {
updateAttemptNumber(message.attemptNumber);
}
} catch (error) {
log.error("SET_STATE error", { error });
}
});
},
onDisconnect: async (socket, handler, sender, logger) => {
this.#platformSocket?.send("LOG", {
metadata: socket.data,
text: "disconnect",
});
try {
this.#platformSocket?.send("LOG", {
metadata: socket.data,
text: "disconnect",
});
} catch (error) {
logger.error("onDisconnect error", { error });
}
},
handlers: {
TASK_HEARTBEAT: async (message) => {
Expand Down

0 comments on commit 9bba3cf

Please sign in to comment.