-
-
Notifications
You must be signed in to change notification settings - Fork 62
Add test cases for multiple mapper errors with stop on error #49
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
Conversation
huntharo
commented
Sep 7, 2021
•
edited
Loading
edited
- Add test cases that demonstrate a single exception being rejected when all mappers fail and stop on error is set
When |
When |
Right, but the mappers have already been started. Those other mappers will not be canceled when the first error is encountered. They will run to completion. As such, I think the behavior should be: stop dispatching new work, but catch all exceptions for already started items and return them. I agree that the current implementation does not result in unhandled promise rejections or uncaught exceptions. I'm not positive how this should work, but it seems wrong that the default behavior will actually start and finish all of the mappers if one of them throws but it only bubbles up 1 random exception even if all of them throw. In any case, if you decide to keep the current behavior then I can just change the failing test to capture the current behavior to ensure that these behaviors do not accidentally change in the future. |
That's how
Yeah, I prefer catching all errors, but only returning the first one. |
Fair point. I think a distinction here is that with A point I'm concerned about here is:
To maintain consistency with Note that setting
Ok, let me know what you think of either a doc update with a caveat or exposing an array of mappers that are running when throwing due to |
Your issue seems to be more about async/await & promises not having a good cancellation story though, but that's a flaw in the language, not just this package. I do want to support AbortController at some point, while far from ideal, get's us closer: #51 |
I think the correct approach is to do #51 and recommend supporting cancellation in the async tasks they do in the mapper.
IMHO, that would be very unexpected behavior and could cause so many other problems. Errors should not be delayed by default. For example, what if one of the mappers it has to wait on takes a very long time to complete, and in the meantime, some other error is thrown somewhere else in the app, and this error is then forever hidden. |
Supporting cancellation of the mapper tasks would be helpful here, but it still wouldn't allow deterministically waiting until all of the mappers have completed or exited, right? So a programmer still could not write code that said "what for that failure to completely stop, then do this". Perhaps we need to borrow from
|
|
Yes that works. Would you accept a documentation caveat being added to the |
Sure, but try to keep it succinct. It would be nice if it also mentioned #51, so people would be incentivized to contribute towards that feature. |
52abbee
to
23c2cd8
Compare
I added a doc note... I think this one is ready? |
readme.md
Outdated
@@ -70,6 +70,8 @@ Number of concurrently pending promises returned by `mapper`. | |||
Type: `boolean`\ | |||
Default: `true` | |||
|
|||
When set to `true`, the first mapper rejection will be rejected back to the consumer. Caveat: any already-started async mappers will continue to run until they resolve or reject but they cannot be awaited as their promises are not exposed; in the case of infinite concurrency with sync iterables *all* mappers will be started on startup and will continue after a rejection. [Issue #51](issues/51) can be implemented to address additional exception and abort use cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit verbose.
And you also need to update index.d.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
test.js
Outdated
}), | ||
{message: 'Oops! 1'} | ||
); | ||
// Note: all 3 mappers get invoked, all 3 throw, even with stop on error this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Note: all 3 mappers get invoked, all 3 throw, even with stop on error this | |
// Note: All 3 mappers get invoked, all 3 throw, even with `{stopOnError: true}` this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
- Add a failing test case to indicate that only 1 of the mapper errors is catchable when stop on error is true and many mappers throw an exception - With concurrent mappers it seems that exceptions should throw an AggregateError when stop on error is true and more than 1 concurrent mapper throws - the iteration of new input items should stop immediately, but all invoked mappers need to finish and all of their exceptions should be bundled and rejected at once - maybe?
- Note: the doc note is now ~25% shorter
5792f9b
to
3cb5885
Compare
Thanks :) |
Co-authored-by: Sindre Sorhus <[email protected]>