Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Could you help me to custom an groovy InvalidInputException?

Rafael Costa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2022

If I throw it, everything is ok:

error = new InvalidInputException("Main error message:")
throw error

 But if I add errors, the main message is replaced to a default error message:

error = new InvalidInputException("Main error message:")
error.addError("error1","error msg")
throw error

You already saw it and know how solve?

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Andrea Pannitti
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 14, 2022

Hi @Rafael Costa,

The class you're using is the class:

com.opensymphony.workflow.InvalidInputException

This class distinguishes errors and generic errors. Thus, within it, an error map and a list for generic errors are populated.

You can find the source code of this class here.

As you will notice, the instruction:

error.addError("error1","error msg")

It's equivalent to education:

error.errors.put("error1","error msg")

So, you're populating the errors map.

Instead, if you use the instruction with only a parameter:

error.addError("error1")

You're populating the generic errors list.

You can observe this by running the following code from the ScriptRunner console:

import com.opensymphony.workflow.InvalidInputException

def error = new InvalidInputException("Main error message:")
error.addError("error1","error msg")
error.errors.put("error2", "error msg2")
error.addError("errorA")
error.addError("errorB")
throw error

I hope this helps you to resolve your doubts.

TAGS
AUG Leaders

Atlassian Community Events