camunda / feel-scala

FEEL parser and interpreter written in Scala
https://camunda.github.io/feel-scala/
Apache License 2.0
119 stars 46 forks source link

Can't access suppressed failures of an EvaluationResult from Java #726

Open saig0 opened 9 months ago

saig0 commented 9 months ago

Describe the bug From a Java application, I can't access the suppressed failures of an EvaluationResult smoothly. The result returns the failures as a Scala list that is not easy to consume from Java code. See here

To Reproduce Steps to reproduce the behavior:

  1. From Java code, access the suppressed failures of an EvaluationResult.
    final java.util.List<EvaluationFailure> failures = result.suppressedFailures();
  2. Verify that the code snipped doesn't compile because it returns a Scala list

Expected behavior From Java code, I can't access the list of evaluation failures natively (i.e. without any type transformation).

Related to https://github.com/camunda/feel-scala/issues/539.

Environment

saig0 commented 9 months ago

Workaround

In my Java code, I use the following snippet to collect the suppressed failures:

private static List<FeelEvaluationWarning> collectEvaluationWarnings(EvaluationResult result) {
    final var warnings = new ArrayList<FeelEvaluationWarning>();
    result
        .suppressedFailures()
        .foreach(
            failure -> {
              final var warning =
                  FeelEvaluationWarning.of(
                      failure.failureType().toString(), failure.failureMessage());
              warnings.add(warning);
              return null;
            });
    return warnings;
  }