Skip to content

Commit b8a8e1d

Browse files
authored
Merge pull request #405 from constructive-io/copilot/sub-pr-404
Add stack trace logging to error handlers in job workers
2 parents 2c0e84c + 05b2162 commit b8a8e1d

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

jobs/job-scheduler/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ export default class Scheduler {
193193
) => {
194194
if (err) {
195195
log.error('Error connecting with notify listener', err);
196+
if (err instanceof Error && err.stack) {
197+
log.debug(err.stack);
198+
}
196199
// Try again in 5 seconds
197200
// should this really be done in the node process?
198201
setTimeout(this.listen, 5000);
@@ -207,7 +210,10 @@ export default class Scheduler {
207210
});
208211
client.query('LISTEN "scheduled_jobs:insert"');
209212
client.on('error', (e: unknown) => {
210-
log.error('Error with database notify listener');
213+
log.error('Error with database notify listener', e);
214+
if (e instanceof Error && e.stack) {
215+
log.debug(e.stack);
216+
}
211217
release();
212218
this.listen();
213219
});

jobs/knative-job-worker/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ export default class Worker {
176176
release: () => void
177177
) => {
178178
if (err) {
179-
log.error('Error connecting with notify listener');
179+
log.error('Error connecting with notify listener', err);
180+
if (err instanceof Error && err.stack) {
181+
log.debug(err.stack);
182+
}
180183
// Try again in 5 seconds
181184
// should this really be done in the node process?
182185
setTimeout(this.listen, 5000);
@@ -190,7 +193,10 @@ export default class Worker {
190193
});
191194
client.query('LISTEN "jobs:insert"');
192195
client.on('error', (e: unknown) => {
193-
log.error('Error with database notify listener', String(e));
196+
log.error('Error with database notify listener', e);
197+
if (e instanceof Error && e.stack) {
198+
log.debug(e.stack);
199+
}
194200
release();
195201
this.listen();
196202
});

jobs/knative-job-worker/src/req.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const request = (
6767
function (error: unknown) {
6868
if (error) {
6969
log.error(`request error for job[${jobId}] fn[${fn}]`, error);
70+
if (error instanceof Error && error.stack) {
71+
log.debug(error.stack);
72+
}
7073
return reject(error);
7174
}
7275
log.debug(`request success for job[${jobId}] fn[${fn}]`);

0 commit comments

Comments
 (0)