From ce61a07e280665a3cc82ffdb753df61296402dcd Mon Sep 17 00:00:00 2001 From: Matheus Robert Lichtnow Date: Mon, 9 Mar 2026 12:26:12 -0300 Subject: [PATCH] fix: guard against missing handler in worker executeJob Fail the job and emit a failure event instead of crashing when no handler is registered for an acquired job's pattern. --- src/worker.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/worker.ts b/src/worker.ts index 34a0ac9..8aaa464 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -243,10 +243,21 @@ export class Worker { this.activeJobs.set(runnerId, job); const handler = this.handlers[job.pattern]; + + if (!handler) { + const error = new Error( + `No handler registered for pattern "${job.pattern}" (job ${job.id})`, + ); + await this.tools.failJob(job.id, error.message); + this.events.emit("failure", { runnerId, job, error, durationMs: 0 }); + this.activeJobs.delete(runnerId); + return; + } + const startTime = Date.now(); try { - await handler!(job); + await handler(job); const durationMs = Date.now() - startTime; await this.tools.completeJob(job.id); this.events.emit("success", { runnerId, job, durationMs });