Skip to content

Commit 5c0e869

Browse files
authored
feat: Handle unhandled errors in worker thread by not crashing parent thread (#937)
feat: Handle unhandled errors in worker thread by not crashing parent thread, and properly log the handled error
1 parent 4ca84d0 commit 5c0e869

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

background-charm-service/src/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { SpaceManager } from "./space-manager.ts";
66
import { useCancelGroup } from "@commontools/runner";
77

88
export interface BackgroundCharmServiceOptions {
9-
identity: Identity,
10-
toolshedUrl: string,
9+
identity: Identity;
10+
toolshedUrl: string;
1111
}
1212

1313
export class BackgroundCharmService {

background-charm-service/src/worker-controller.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export class WorkerController {
7575
// FIXME(ja): what should we do if the worker is erroring?
7676
// perhaps restart the worker?
7777
this.worker.onerror = (err) => {
78-
log(`${this.did}: Worker error:`, err, {
79-
error: true,
80-
});
78+
log(`${this.did}: Worker error:`, { error: true }, err);
79+
// If not prevented, error is rethrown in this context.
80+
err.preventDefault();
8181
};
8282
}
8383

@@ -87,9 +87,11 @@ export class WorkerController {
8787
toolshedUrl,
8888
rawIdentity: identity.serialize(),
8989
}).catch((err) => {
90-
log(`Worker controller ${this.did} worker setup failed:`, err, {
91-
error: true,
92-
});
90+
log(
91+
`Worker controller ${this.did} worker setup failed:`,
92+
{ error: true },
93+
err,
94+
);
9395
}).then(() => {
9496
this.ready = true;
9597
log(`Worker controller ${this.did} ready for work`);

0 commit comments

Comments
 (0)