I'm trying to write wrappers on Jira API functions with exception handling.
void setField(String field, value, MutableIssue issue = this.issue) {
def cfo = cfm.getCustomFieldObject(field)
try {
issue.setCustomFieldValue(cfo, value)
} catch (e) {
LOG.error('Test')
}
I purposefully try to insert wrong type of value into given customfield to trigger an exception. And it does
Caught exception while attempting to perform action 181 from workflow 1081660 on issue 'xxx'
java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.util.Collection (java.lang.Integer and java.util.Collection are in module java.base of loader 'bootstrap')
However it is not being caught by the try-catch block. Why is that? Code is in groovy
Hi @Jakub Cieplinski ,
based on the error it seems that you are trying to put and integer to a collection custom field (it could be a selectlist, versions, components field).
You should set field value based on the field type (double for Numeric field, String for text field, Option for single selectlist, Collection<Option> for multiselect, Collection<Version> for version field and so on).
Hope this helps,
Fabio
Hi @Fabio Racobaldo _Herzum_ , yes I'm aware of that. As I said I'm doing it on purpose to explicitly trigger that exception because I want to be able to handle it in try-catch block. But it ignores my catch and I would like to know why it does that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try using the ClassCastException provided by (java.lang) in the catch block :
} catch (ClassCastException e) {
LOG.error('Test')
}
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It didn't help. Although I just went through log message once again and realized it said
Caught exception while attempting to perform action
So it seems to me like Jira itself catches this exception before I can. I suppose this cannot be circumvented?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What log file are you checking? How do you add your code to jira (addon, scriptrunner)?
Did you add your class to logging and profiling?
In order to provide you help, we need to have all information.
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm using scriptrunner app and checking atlassian-jira.log in jira-home/log
Class calls are triggered by intermediate script added as a post function to ticket transition
I'm not familiar with adding my classes to logging and profiling
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please use this thread to setup logger https://community.atlassian.com/t5/Jira-questions/How-can-I-log-with-Script-Runner/qaq-p/775419
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I'm using the scriptrunner logging implementation which works fine. The logging code in catch statement is not executed because the exception is not caught by my class but by some java code inside jira
Caught exception while attempting to perform action 181 from workflow 1081660 on issue 'xxx'
java.lang.ClassCastException:
I want to know if this can be somehow circumvented so Jira passes those exceptions further so I can handle them myself
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.