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

forceOnAll will catch exception from resolving Stream element #39

Merged
merged 8 commits into from
Sep 26, 2024

Conversation

runeflobakk
Copy link
Member

@runeflobakk runeflobakk commented Sep 26, 2024

The expectation from forceOnAll is to force an attempt of execution of an operation on all elements. This works as intended when the elements are already resolved, as they are when passed as an array. But a Stream may resolve it's elements from any source, also sources which can typically fail, e.g. if the element are sourced from an API request. By default, an exception occurring when the Stream tries to yield an element for the pipeline of filters, maps, etc, will abort the Stream terminal operation, and be immediately thrown.

In order to "tap into" the resolving logic, the approach of flatmapping to a (potential) exception using the regular Stream API has now been replaced with a bit more "low-level" use of a Spliterator which will invoke the intended side-effect, and catch any exception which can happen for both trying to advance to the next element, and from the operation itself on wishes to execute on a successfully resolved element.

This subtly changes the behavior of forceOnAll, but I consider this an alignment to what one expects from forceOnAll.


I also added DiggStreams.describeCharacteristics to get a String description of the characteristics of a Spliterator, which is represented as a bit-string, and difficult to resolve which actual characteristics are enabled. It is not used by any other code in Digg, but was useful when implementing/debugging the FlatMapToExceptionSpliterator, so I decided to include it. It does what it says on the tin, yields a text description, and you should not rely on the String for anything other than information.

A little bit unfortunate and assuming, but it is existing behavior and
must be preserved to avoid breaking stuff.
This enables mock usage validation by Mockito.
Copy link
Member

@eivinhb eivinhb left a comment

Choose a reason for hiding this comment

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

🎸

@runeflobakk runeflobakk merged commit 67ac332 into main Sep 26, 2024
4 checks passed
@runeflobakk runeflobakk deleted the catch-exception-from-resolving-stream-element branch September 26, 2024 15:49
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.

2 participants