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

[Feature Request]: Better assertion error message for PAssert.thatSingleton #28612

Closed
1 of 15 tasks
mkuthan opened this issue Sep 22, 2023 · 1 comment · Fixed by #31761
Closed
1 of 15 tasks

[Feature Request]: Better assertion error message for PAssert.thatSingleton #28612

mkuthan opened this issue Sep 22, 2023 · 1 comment · Fixed by #31761

Comments

@mkuthan
Copy link
Contributor

mkuthan commented Sep 22, 2023

What would you like to happen?

If element doesn't exist in empty PCollection - PAssert.thatSingleton emits the following error message:

java.util.NoSuchElementException
org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.util.NoSuchElementException
(stack trace)
Caused by: java.util.NoSuchElementException
	at java.base/java.util.ArrayList$Itr.next(ArrayList.java:970)
	at org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterators.getOnlyElement(Iterators.java:309)
	at org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables.getOnlyElement(Iterables.java:263)
	at org.apache.beam.sdk.testing.PAssert$SingletonCheckerDoFn.processElement(PAssert.java:1613)

If element is not the only element in PCollection - PAssert.thatSingleton emits the following error message:

java.lang.IllegalArgumentException: expected one element but was: (...)
org.apache.beam.sdk.Pipeline$PipelineExecutionException: java.lang.IllegalArgumentException: expected one element but was: (...)
(stack trace)
Caused by: java.lang.IllegalArgumentException: expected one element but was: (...)	at org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterators.getOnlyElement(Iterators.java:323)
	at org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables.getOnlyElement(Iterables.java:263)
	at org.apache.beam.sdk.testing.PAssert$SingletonCheckerDoFn.processElement(PAssert.java:1613)

For presented scenarios assertion errors doesn't really help - there is no assertion call site info.

private static class SingletonCheckerDoFn ... {
@ProcessElement
    public void processElement(ProcessContext c) {
      ActualT actualContents = Iterables.getOnlyElement(c.element()); // <- runtime exception here
      c.output(doChecks(site, actualContents, checkerFn)); // <- no doCheck call with proper assertion site info
    }
}

Issue Priority

Priority: 3 (nice-to-have improvement)

Issue Components

  • Component: Python SDK
  • Component: Java SDK
  • Component: Go SDK
  • Component: Typescript SDK
  • Component: IO connector
  • Component: Beam examples
  • Component: Beam playground
  • Component: Beam katas
  • Component: Website
  • Component: Spark Runner
  • Component: Flink Runner
  • Component: Samza Runner
  • Component: Twister2 Runner
  • Component: Hazelcast Jet Runner
  • Component: Google Cloud Dataflow Runner
@Amar3tto
Copy link
Contributor

Amar3tto commented Jul 3, 2024

.take-issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants