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

Remove unnecessary lambda pointer from first(predicate) error message. #4220

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

Luceium
Copy link
Contributor

@Luceium Luceium commented Sep 7, 2024

When first is called on a flow that doesn't satisfy the predicate it throws a NoSuchElementException with the message "Expected at least one element matching the predicate $predicate". The use of $predicate implies printing out the lambda however, the lambda's pointer is printed instead.

As far as I know, getting the lambda's string representation is not feasible. Therefore I feel it is best to remove $predicate from the error message to make it more readable and remove unnecessary information.

For example, running
flowOf(1, 2, 3).first {it > 4} https://pl.kotl.in/jjalTWjTt
returns the error message

Exception in thread "main" java.util.NoSuchElementException: Expected at least one element matching the predicate Function2<java.lang.Integer, kotlin.coroutines.Continuation<? super java.lang.Boolean>, java.lang.Object>
 at kotlinx.coroutines.flow.FlowKt__ReduceKt.first (Reduce.kt:114) 
 at kotlinx.coroutines.flow.FlowKt.first (:1) 
 at kotlinx.coroutines.guide.exampleFlow07.FileKt.main (File.kt:8) 

Where the predicate flowOf(1, 2, 3).first {it > 4} evaluates too Function2<java.lang.Integer, kotlin.coroutines.Continuation<? super java.lang.Boolean>, java.lang.Object>

I feel that there is no added value from the lambda pointer being printed. It seems better for the developer to use the line number and read the lambda from source code.

@GIgako19929
Copy link

  • [ ]

@Luceium
Copy link
Contributor Author

Luceium commented Sep 17, 2024

Could you explain your comment? I can't find anything in the contributor guide about it.

@qwwdfsad qwwdfsad self-requested a review September 18, 2024 19:33
Copy link
Contributor

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

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

Thanks!

@qwwdfsad qwwdfsad merged commit cf4fcd1 into Kotlin:develop Sep 19, 2024
1 check passed
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