-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NODE-5311): construct error messages for AggregateErrors in Node1…
…6+ (#3683)
- Loading branch information
1 parent
c0c3d99
commit 98b7bdf
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { MongoClient, MongoError, MongoServerSelectionError } from '../../../src'; | ||
|
||
describe('Error (Integration)', function () { | ||
describe('AggregateErrors', function () { | ||
for (const { errors, message } of [ | ||
{ | ||
errors: [], | ||
message: | ||
'AggregateError has an empty errors array. Please check the `cause` property for more information.' | ||
}, | ||
{ errors: [new Error('message 1')], message: 'message 1' }, | ||
{ | ||
errors: [new Error('message 1'), new Error('message 2')], | ||
message: 'message 1, message 2' | ||
} | ||
]) { | ||
it( | ||
`constructs the message properly with an array of ${errors.length} errors`, | ||
{ requires: { nodejs: '>=16' } }, | ||
() => { | ||
const error = new AggregateError(errors); | ||
const mongoError = new MongoError(error); | ||
|
||
expect(mongoError.message).to.equal(message); | ||
} | ||
); | ||
} | ||
|
||
context('when the message on the AggregateError is non-empty', () => { | ||
it(`uses the AggregateError's message`, { requires: { nodejs: '>=16' } }, () => { | ||
const error = new AggregateError([new Error('non-empty')]); | ||
error.message = 'custom error message'; | ||
const mongoError = new MongoError(error); | ||
expect(mongoError.message).to.equal('custom error message'); | ||
}); | ||
}); | ||
|
||
it('sets the AggregateError to the cause property', { requires: { nodejs: '>=16' } }, () => { | ||
const error = new AggregateError([new Error('error 1')]); | ||
const mongoError = new MongoError(error); | ||
expect(mongoError.cause).to.equal(error); | ||
}); | ||
}); | ||
|
||
it('NODE-5296: handles aggregate errors from dns lookup', async function () { | ||
const error = await MongoClient.connect('mongodb://localhost:27222', { | ||
serverSelectionTimeoutMS: 1000 | ||
}).catch(e => e); | ||
expect(error).to.be.instanceOf(MongoServerSelectionError); | ||
expect(error.message).not.to.be.empty; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
const { satisfies } = require('semver'); | ||
|
||
/** | ||
* Filter for specific nodejs versions | ||
* | ||
* example: | ||
* metadata: { | ||
* requires: { | ||
* nodejs: '>=14' | ||
* } | ||
* } | ||
*/ | ||
class NodeVersionFilter { | ||
filter(test) { | ||
if (!test.metadata) return true; | ||
if (!test.metadata.requires) return true; | ||
if (!test.metadata.requires.nodejs) return true; | ||
|
||
return satisfies(process.version, test.metadata.requires.nodejs); | ||
} | ||
} | ||
|
||
module.exports = NodeVersionFilter; |