Guides
Errors and Logging

Error and Logging

Whenever Sidetrack encounters an unhandled exception while running your job, the error and stack trace will be appended to the errors field for that job, and the job will be marked as failed (or retrying if more attempts are available).

While you can always refer to the errors field on the job to see what went wrong, you should consider adding logs.

ts
import { Sidetrack, SidetrackJobWithPayload } from "sidetrack";
 
const onboardUser = async (job: SidetrackJobWithPayload<{ email: string }>) => {
try {
// do something
} catch (error) {
logger.error(`Job ${job.id} failed`, error);
throw error;
}
};
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string };
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!,
},
queues: {
userOnboarding: {
handler: onboardUser,
},
},
});
ts
import { Sidetrack, SidetrackJobWithPayload } from "sidetrack";
 
const onboardUser = async (job: SidetrackJobWithPayload<{ email: string }>) => {
try {
// do something
} catch (error) {
logger.error(`Job ${job.id} failed`, error);
throw error;
}
};
 
const sidetrack = new Sidetrack<{
userOnboarding: { email: string };
}>({
databaseOptions: {
connectionString: process.env["DATABASE_URL"]!,
},
queues: {
userOnboarding: {
handler: onboardUser,
},
},
});