mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-17 23:44:39 -05:00
Removed use of native JS Error objects
closes https://linear.app/tryghost/issue/CORE-55/fix-errors-in-utils-repo-job-manager - The latest ESLint rules forbid use of native JS errors, updated the codebase before bumping the ESLint version
This commit is contained in:
parent
be6c8ea390
commit
4b70c7e0c0
1 changed files with 8 additions and 4 deletions
|
@ -3,7 +3,7 @@ const fastq = require('fastq');
|
||||||
const later = require('@breejs/later');
|
const later = require('@breejs/later');
|
||||||
const Bree = require('bree');
|
const Bree = require('bree');
|
||||||
const pWaitFor = require('p-wait-for');
|
const pWaitFor = require('p-wait-for');
|
||||||
const errors = require('@tryghost/errors');
|
const {IgnitionError, IncorrectUsageError} = require('@tryghost/errors');
|
||||||
const isCronExpression = require('./is-cron-expression');
|
const isCronExpression = require('./is-cron-expression');
|
||||||
const assembleBreeJob = require('./assemble-bree-job');
|
const assembleBreeJob = require('./assemble-bree-job');
|
||||||
|
|
||||||
|
@ -67,7 +67,9 @@ class JobManager {
|
||||||
if (typeof job === 'string') {
|
if (typeof job === 'string') {
|
||||||
name = path.parse(job).name;
|
name = path.parse(job).name;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Name parameter should be present if job is a function');
|
throw new IncorrectUsageError({
|
||||||
|
message: 'Name parameter should be present if job is a function'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +81,9 @@ class JobManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((schedule.error && schedule.error !== -1) || schedule.schedules.length === 0) {
|
if ((schedule.error && schedule.error !== -1) || schedule.schedules.length === 0) {
|
||||||
throw new Error('Invalid schedule format');
|
throw new IncorrectUsageError({
|
||||||
|
message: 'Invalid schedule format'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logging.info(`Scheduling job ${name} at ${at}. Next run on: ${later.schedule(schedule).next()}`);
|
this.logging.info(`Scheduling job ${name} at ${at}. Next run on: ${later.schedule(schedule).next()}`);
|
||||||
|
@ -105,7 +109,7 @@ class JobManager {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// NOTE: each job should be written in a safe way and handle all errors internally
|
// NOTE: each job should be written in a safe way and handle all errors internally
|
||||||
// if the error is caught here jobs implementaton should be changed
|
// if the error is caught here jobs implementaton should be changed
|
||||||
this.logging.error(new errors.IgnitionError({
|
this.logging.error(new IgnitionError({
|
||||||
level: 'critical',
|
level: 'critical',
|
||||||
errorType: 'UnhandledJobError',
|
errorType: 'UnhandledJobError',
|
||||||
message: 'Processed job threw an unhandled error',
|
message: 'Processed job threw an unhandled error',
|
||||||
|
|
Loading…
Add table
Reference in a new issue