Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint: resolve prefer-promise-reject-errors violations #1040

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/integration/other/analytics-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ describe('analytics task queries', function () {

// fail the processing of this latest event
let event = (await container.Audits.getLatestByAction('submission.attachment.update')).get();
// eslint-disable-next-line prefer-promise-reject-errors
const jobMap = { 'submission.attachment.update': [ () => Promise.reject({ uh: 'oh' }) ] };
const jobMap = { 'submission.attachment.update': [ () => Promise.reject(new Error()) ] };
await promisify(workerQueue(container, jobMap).run)(event);

// should still be 0 because the failure count is only at 1, needs to be at 5 to count
Expand Down Expand Up @@ -374,8 +373,7 @@ describe('analytics task queries', function () {
.attach('xml_submission_file', Buffer.from(testData.instances.clientAudits.one), { filename: 'data.xml' })
.expect(201);

// eslint-disable-next-line prefer-promise-reject-errors
const jobMap = { 'submission.attachment.update': [ () => Promise.reject({ uh: 'oh' }) ] };
const jobMap = { 'submission.attachment.update': [ () => Promise.reject(new Error()) ] };
const eventOne = (await container.Audits.getLatestByAction('submission.attachment.update')).get();
await promisify(workerQueue(container, jobMap).run)(eventOne);

Expand Down
10 changes: 5 additions & 5 deletions test/integration/task/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('task: auditing', () => {
it('should fault but passthrough on log failure', testTask(({ Audits }) => {
// hijack Audit.log to crash. new container is made for each test so we don't have
// to restore a working one.
// eslint-disable-next-line prefer-promise-reject-errors, no-param-reassign
Audits.log = () => Promise.reject(false);
// eslint-disable-next-line no-param-reassign
Audits.log = () => Promise.reject(new Error());
return auditing('testAction', Promise.resolve(true))
.then((result) => {
// too difficult to test stderr output.
Expand All @@ -80,12 +80,12 @@ describe('task: auditing', () => {
// ditto above.
// eslint-disable-next-line no-param-reassign
Audits.log = () => Promise.reject(Problem.user.missingParameter({ field: 'test' }));
// eslint-disable-next-line prefer-promise-reject-errors
return auditing('testAction', Promise.reject(true))
return auditing('testAction', Promise.reject(new Error('uhoh')))
.then(identity, (result) => {
// too difficult to test stderr output.
process.exitCode.should.equal(1);
result.should.equal(true);
result.should.be.instanceOf(Error);
result.message.should.equal('uhoh');
});
}));
});
Expand Down
19 changes: 8 additions & 11 deletions test/integration/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ describe('worker', () => {
const hijackedContainer = container.with({ Sentry });

const event = { id: -1, action: 'test.event', failures: 0 };
// eslint-disable-next-line prefer-promise-reject-errors
const jobMap = { 'test.event': [ () => Promise.reject({ uh: 'oh' }) ] };
const jobMap = { 'test.event': [ () => Promise.reject(new Error('uhoh')) ] };
await promisify(workerQueue(hijackedContainer, jobMap).run)(event);
captured.should.eql({ uh: 'oh' });
captured.should.be.instanceOf(Error);
captured.message.should.equal('uhoh');
}));

// ideally we'd test that the error gets written to stderr but i don't like
Expand All @@ -100,8 +100,7 @@ describe('worker', () => {
const hijackedContainer = container.with({ Sentry });

const event = { id: -1, action: 'test.event', failures: 0 };
// eslint-disable-next-line prefer-promise-reject-errors
const jobMap = { 'test.event': [ () => Promise.reject({ uh: 'oh' }) ] };
const jobMap = { 'test.event': [ () => Promise.reject(new Error()) ] };
await promisify(workerQueue(hijackedContainer, jobMap).run)(event);
// not hanging is the test here.
}));
Expand All @@ -115,8 +114,7 @@ describe('worker', () => {
await Audits.log(alice.actor, 'submission.attachment.update', alice.actor);
const event = (await Audits.getLatestByAction('submission.attachment.update')).get();

// eslint-disable-next-line prefer-promise-reject-errors
const jobMap = { 'submission.attachment.update': [ () => Promise.reject({ uh: 'oh' }) ] };
const jobMap = { 'submission.attachment.update': [ () => Promise.reject(new Error()) ] };
await promisify(workerQueue(container, jobMap).run)(event);
const after = (await Audits.getLatestByAction('submission.attachment.update')).get();
should.not.exist(after.claimed);
Expand All @@ -133,8 +131,7 @@ describe('worker', () => {

const jobMap = { 'submission.attachment.update': [
({ Audits: AuditQuery }) => AuditQuery.log(alice.actor, 'dummy.event', alice.actor),
// eslint-disable-next-line prefer-promise-reject-errors
() => Promise.reject({ uh: 'oh' }) ] };
() => Promise.reject(new Error()) ] };
await promisify(workerQueue(container, jobMap).run)(event);

const dummyEvent = (await Audits.getLatestByAction('dummy.event'));
Expand Down Expand Up @@ -364,8 +361,8 @@ select count(*) from audits where action='submission.attachment.update' and proc
if (q.sql.startsWith('\nwith q as')) {
if (failed) return container.all(q);
failed = true;
// eslint-disable-next-line prefer-promise-reject-errors, no-async-promise-executor
return new Promise(async (_, reject) => { await millis(5); reject('not this time'); });
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (_, reject) => { await millis(5); reject(new Error()); });
}
};
const jobMap = { 'submission.attachment.update': [ () => Promise.resolve() ] };
Expand Down
3 changes: 1 addition & 2 deletions test/unit/util/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ describe('stream utils', () => {

it('should reject if any stream rejects', () => {
const fail = (stream) => new Promise((_, reject) => {
// eslint-disable-next-line prefer-promise-reject-errors
stream.on('data', (x) => { if (x === 'three') reject(false); });
stream.on('data', (x) => { if (x === 'three') reject(new Error()); });
});
return consumeAndBuffer(fromObjects([ 'one', 'two', 'three' ]), consumer('two'), fail)
.should.be.rejected();
Expand Down