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

Handling of errors in find & some #1248

Closed
megawac opened this issue Jul 21, 2016 · 5 comments
Closed

Handling of errors in find & some #1248

megawac opened this issue Jul 21, 2016 · 5 comments

Comments

@megawac
Copy link
Collaborator

megawac commented Jul 21, 2016

Upon some reflection I don't like how we handle errors in the internal createTester.

When an error occurs we resolve the callback resolves immediately; however, if in the case of some or detect, if the iteratee returned truthy we would have exited createTester successfully.

I think the correct approach would be to continue upon error and determine whether any item was truthy.

@aearly
Copy link
Collaborator

aearly commented Jul 30, 2016

I think exiting immediately on an error is the "correct" thing to do here. _.some(arr, (v) => { throw new Error(); return true }) would throw, not return true.

If the error occurred on the iteration loop that called-back true, would the some function callback true? In that specific case, I think the error should override the true value.

@megawac
Copy link
Collaborator Author

megawac commented Aug 3, 2016

Sure, but in _.some or Array.prototype.somes cases its serial and can gaurentee which item it will error on. In the async case (for not *Series) we are racing to determine whether a) a error occurs b) a test passes. Seems sketch

If the error occurred on the iteration loop that called-back true, would the some function callback true? In that specific case, I think the error should override the true value.

No that's definitely counted as an error. When checking an individual callback, error should always takes precedence over the rest of the resolve arguments.
In detect and some however, I'm not sure if an error in one warrants a error in all.

@aearly
Copy link
Collaborator

aearly commented Aug 4, 2016

Ah, I see, there could be some race conditions in the parallel case, or there could be conflicting results in the parallel case. Not sure what the correct thing to do is. Consider this example:

_.some(_.range(10), function (num) {
  if (num > 5) throw new Error();
  return num === 5;
}

This won't throw with Lodash, but that is just an artifact of its short-circuiting. But should it? Half the values would throw an error if they were iterated over. If it were iterated in reverse, it would throw every time, even though the some condition would be satisfied.

I'm trying to think of a real world example with Async. Would you want to know that one of your iteration steps produced an error, even if the find/some/every condition was satisfied?

@megawac
Copy link
Collaborator Author

megawac commented Feb 8, 2017

Related #591

@aearly
Copy link
Collaborator

aearly commented Mar 9, 2019

Hmnn, this has been open for a long time, and I'm not convinced it's still an issue now that we have tryEach.

@aearly aearly closed this as completed Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants