How to throw an exception because the issue has no components in ScriptRunner postfunction

51 Views Asked by At

I am using Scriptrunner and I would like to throw an exception because the issue has no components as shown below:  enter image description here

How can I do that? 

I am using the following code and I am checking if the components are empty but the error is not thrown. How can I fix this?

package SuperFeature

import com.opensymphony.workflow.WorkflowException

def components = issue.components

log.warn("MOUNA COMPONENTS "+components)

if(components.empty) {

         log.warn("MOUNA EMPTY")

          throw new WorkflowException("Issue does not have components")

}
1

There are 1 best solutions below

0
Andrii Maliuta On BEST ANSWER

When you use ScriptEunner WEB Console, you should return some value, throwing the Exception will not work in most cases. You can structure the code of the script in such a way that you break/stop operation or return false/null/etc. depending on who is the consumer of the Error/Exception.