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

fix: Handle errors thrown in user callbacks in each #869

Merged
merged 7 commits into from
Jan 6, 2023

Conversation

Hunga1
Copy link
Contributor

@Hunga1 Hunga1 commented Jan 4, 2023

Fixes issue where errors thrown in user callbacks are not bubbled up. Any errors thrown in user provided callback functions in the each function will now be caught and passed to the user provided done call.

The each function will now return a promise instead of void. The promise will resolve when all records are processed, the limit is reached, or when the user provided done function param is executed. The promise will reject if an error occurs in the user callback and the optional user provided done function param is not provided, or the user provided done function throws an error.

Added unit tests to test functionality of the each function.

Hunga1 added 2 commits January 4, 2023 11:35
Added logic to Version each function that catches any errors thrown in the user provided callback and calls the user provided done function with the error. If user does not provide a done function, each will return a promise that will reject with any error that occurs. Added unit tests for the Version each function.
@Hunga1 Hunga1 marked this pull request as draft January 5, 2023 20:35
@Hunga1

This comment was marked as outdated.

@Hunga1 Hunga1 marked this pull request as ready for review January 5, 2023 22:38
Copy link
Contributor

@childish-sambino childish-sambino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some minor nits.

lib/base/Version.ts Outdated Show resolved Hide resolved
lib/base/Version.ts Outdated Show resolved Hide resolved
lib/base/Version.ts Outdated Show resolved Hide resolved
Hunga1 added 2 commits January 6, 2023 14:35
Removed the unnecessary nested try, catch block and conditional test if the callback is undefined. Refactored the function code docs from jsdoc to tsdoc.
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

81.0% 81.0% Coverage
0.0% 0.0% Duplication

@Hunga1 Hunga1 merged commit 797127e into 4.0.0-rc Jan 6, 2023
@Hunga1 Hunga1 deleted the each_callback_error_handling branch January 6, 2023 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants