-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(NODE-5296): construct error messages for AggregateErrors in Node16+ #3682
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
edf6bf0
asdf
baileympearson 10b9f9e
improve assertion
baileympearson 819e472
remove unused import
baileympearson 045606a
add additional logic to the error constructor
baileympearson 8c91358
address comments
baileympearson 34f19e1
skip on node16-
baileympearson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 '../../mongodb'; | ||
|
||
describe('Error (Integration)', function () { | ||
nbbeeken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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,26 @@ | ||
'use strict'; | ||
|
||
const { satisfies } = require('semver'); | ||
|
||
/** | ||
* Filter for specific nodejs versions | ||
* | ||
* example: | ||
* metadata: { | ||
* requires: { | ||
* nodejs: '>=14' | ||
* } | ||
* } | ||
*/ | ||
class NodeVersionFilter { | ||
filter(test) { | ||
const nodeVersionRange = test?.metadata?.requires?.nodejs; | ||
if (!nodeVersionRange) { | ||
return true; | ||
} | ||
|
||
return satisfies(process.version, nodeVersionRange); | ||
} | ||
} | ||
|
||
module.exports = NodeVersionFilter; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.