Skip to content

Commit fe17bfa

Browse files
fix: Properly catch cronjob errors during initialization
1 parent d87cf44 commit fe17bfa

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"branches": 93.51,
3-
"functions": 97.36,
4-
"lines": 98.33,
5-
"statements": 98.17
3+
"functions": 97.61,
4+
"lines": 98.38,
5+
"statements": 98.21
66
}

packages/snaps-controllers/src/cronjob/CronjobController.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ export class CronjobController extends BaseController<
196196
(...args) => this.getBackgroundEvents(...args),
197197
);
198198

199-
this.dailyCheckIn().catch((error) => {
200-
logError(error);
201-
});
199+
this.dailyCheckIn();
202200

203201
this.#rescheduleBackgroundEvents(Object.values(this.state.events));
204202
}
@@ -471,7 +469,7 @@ export class CronjobController extends BaseController<
471469
*
472470
* This is necessary for longer running jobs that execute with more than 24 hours between them.
473471
*/
474-
async dailyCheckIn() {
472+
dailyCheckIn() {
475473
const jobs = this.#getAllJobs();
476474

477475
for (const job of jobs) {
@@ -483,7 +481,9 @@ export class CronjobController extends BaseController<
483481
parsed.hasPrev() &&
484482
parsed.prev().getTime() > lastRun
485483
) {
486-
await this.#executeCronjob(job);
484+
this.#executeCronjob(job).catch((error) => {
485+
logError(error);
486+
});
487487
}
488488

489489
// Try scheduling, will fail if an existing scheduled job is found
@@ -492,10 +492,7 @@ export class CronjobController extends BaseController<
492492

493493
this.#dailyTimer = new Timer(DAILY_TIMEOUT);
494494
this.#dailyTimer.start(() => {
495-
this.dailyCheckIn().catch((error) => {
496-
// TODO: Decide how to handle errors.
497-
logError(error);
498-
});
495+
this.dailyCheckIn();
499496
});
500497
}
501498

0 commit comments

Comments
 (0)