-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.2.6
-
Component/s: Core
-
Empty show more show less
-
Not Needed
When using the promised cursor.forEach (that is, without a callback), any exception thrown from within the iterator does not propagate to the outer awaiting continuation. Further, the exception is treated as unhandled by the node runtime resulting in the application crashing.
Consider this simplified example:
try { await cursor.forEach(doc => { throw new Error('BLAMMO!'); }); } catch(ex) { }
I believe the default expectation of users of this library is that this exception would be thrown from the await continuation.
Unfortunately, the actual result is `uncaught exception: Error: BLAMMO!`
I'm thinking that this invocation https://github.com/mongodb/node-mongodb-native/blob/master/lib/cursor.js#L770 should be wrapped in a try/catch with a reject() call in the catch firewall.
It would be my pleasure to PR this change, if I could get preliminary approval of the approach from the project maintainers.
- duplicates
-
NODE-3231 cursor.forEach() iterator exception does not result in rejected Promise
- Closed