Groovy Assert "internal server error" on assertion failure?

When running a Groovy script in a process, if you have a assertion and it fails, the response is “internal server error”. Is camunda able to capture the java.lang.AssertionError that is thrown on assertion failure?

If the assertion passes, there is not issues, everything continues as expected.

Current workaround is:

try{
  assert value1 == answer1 : "Not the correct answer"

} catch(AssertionError e) {
  throw new Exception(e.getMessage())
}

But this is obviously not the ideal given how often one can use power assertions in groovy.

Hi Stephen,

can you please provide more details about your use case.

Where do you get this response? What do you expect?

You should found the error and the full stacktrace in the log.

How do you want to handle the response?

Best regards,
Philipp

Response is shown in Tasklist. When the assertion error is thrown, the, we don’t get anything in the typical console logs. When you do async, it just get stuck in the task state or script task. It does not show as a error (when using async), it just “gets stuck”. @Philipp_Ossler did you test if the error shows in the console logs?

We would expect that the Assertion error is sent to console and sent to task list UI just as an Exception does.

As for use cases. Have been exploring different ways Groovy assertions can be used to provide a level of business analysis functional testing. At the moment, just working through some use cases of Asserting inputs and outputs, form submissions, gateway logic, “protected” processes variables, and other scenarios where groovy’s power assertions could be used as a level of testing on processes. Especially at an analyst level.

Hi Stephen,

I tested the behavior. When the script is executed by the job executor then the retries of the job are not decreased and no error is reported. You can find the error message only in the server log.

The behavior is different from scripts which throw an exception because an AssertionError is an error and not an exception. In common case, errors should not catch by a program. Also, the Java Script Api says that an ScriptException in thrown when an error occurs.

So, I recommend using a custom function instead of assert and throws an exception (e.g., llegalArgumentException).

However, I created an issue for that.

Best regards,
Philipp

Thanks @Philipp_Ossler jira ticket looks good.