Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[heft] Handle errors when IPC messaging host #4832

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/operation-graph",
"comment": "Handle errors when sending IPC messages to host.",
"type": "patch"
}
],
"packageName": "@rushstack/operation-graph"
}
20 changes: 17 additions & 3 deletions libraries/operation-graph/src/WatchLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ export class WatchLoop implements IWatchLoopState {
let runRequestedFromHost: boolean = true;
let status: OperationStatus = OperationStatus.Ready;

function tryMessageHost(
message: ISyncEventMessage | IRequestRunEventMessage | IAfterExecuteEventMessage
): void {
if (!host.send) {
return reject(new Error('Host does not support IPC'));
}

try {
host.send(message);
} catch (err) {
reject(new Error(`Unable to communicate with host: ${err}`));
}
}

function requestRunFromHost(requestor?: string): void {
if (runRequestedFromHost) {
return;
Expand All @@ -145,15 +159,15 @@ export class WatchLoop implements IWatchLoopState {
requestor
};

host.send!(requestRunMessage);
tryMessageHost(requestRunMessage);
}

function sendSync(): void {
const syncMessage: ISyncEventMessage = {
event: 'sync',
status
};
host.send!(syncMessage);
tryMessageHost(syncMessage);
}

host.on('message', async (message: CommandMessageFromHost) => {
Expand Down Expand Up @@ -189,7 +203,7 @@ export class WatchLoop implements IWatchLoopState {
event: 'after-execute',
status
};
host.send!(afterExecuteMessage);
tryMessageHost(afterExecuteMessage);
}
return;
}
Expand Down
Loading