how to handle exceptions in Insight Post Functions?

Jon Hill September 20, 2018

I've written a fairly detailed Insight Post Function in groovy and it's working well.  I've added a bunch of exception handling and that's working too, but I can't figure out how to send feedback back to the end user when an exception occurs.

For example, if the user selects a particular Insight object in the Jira ticket, then waits a day, then submits the Jira ticket *after* someone else has deleted the original Insight object, my script will return a false.  But the Jira workflow is ignoring that false (and it also ignores unhandled exceptions, just logging them deep in the bowels of the application server), so the user thinks everything is fine.  In fact, the next step in the workflow (send e-mail to user saying that everything went well) executes! 

Is there any way to provide some feedback to the user that not all went well?  Maybe revert the state to the beginning, or send an e-mail, or something?  So far the only idea I've had is to created a boolean Jira field within the project, set that value to the exitcode of my function, and then (maybe) set up some kind of precondition to make sure that the transition can't continue beyond that point.  

Any thoughts would be appreciated.

1 answer

1 accepted

0 votes
Answer accepted
Yinon Negev
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.
September 21, 2018

Hi Jon.

      Although there is no direct way to inform the User of an exception in a Postfunction, you can handle your exception using Groovy Script as Workflow Conditions/Validators, where, if the Groovy returns False, the transition will be blocked and an Error message will be displayed.

Alternatively, to keep your Postfunction as is, and to take advantage of Insight Automation - you can create an "Error" Object Type which will be updated by your Groovy Script when an Exception is occurring. Set up an automation rule to run whenever an Error Type Object is updated, resulting in an email sent to Users in an Attribute. The Error Object may carry the Message you want to send as a Textarea Attribute etc. This idea can be developed further, as you wish...

Insight can be used in many ways to solve different cases. :)

Cheers

Yinon

Team Riada

Jon Hill September 21, 2018

That Error object type is clever!

Jon Hill September 21, 2018

The insight groovy validator ignores my error text and instead just gives the user a scary error message that doesn't help them identify the problem:

It seems that you have tried to perform an illegal workflow operation.

If you think this message is wrong, please contact your JIRA administrators.

 

 
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;

def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11700));

/* If the custom field's name is not ZNY7JHILL it will fail */
log.info(value[0].getName());
if (value != null && "ZNY7JHILLOLD".equals(value[0].getName())) {
return "Don't mess with ZNY7JHILLOLD!";
}
else {
return true;
}

 

The insight object type validator (the IQL one) doesn't even give me an option to display error text, which seems like a really important feature to be missing.  Other non-Insight validators have that feature.

Yinon Negev
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.
September 21, 2018

I would like to recommend you to visit https://jira.riada.se which is our open ticket system for feature requests and verified bugs. You can view, watch, vote etc for issues reported by anyone.

If you can't find an already opened feature request for this, feel free to create a new one.

If you have any issues or questions regarding this, please let us know.

Cheers

Jon Hill September 21, 2018

I've opened a case.  There's at least one other recent case with validators but it's been marked as Low.

Jon Hill September 24, 2018

The ugly validator error message was due to my own ignorance.  I didn't realize that the validator only works for transitions that have screens defined.  Now that I understand this I'll redo my workflow, but it looks like this should be helpful.  I may still need to use your Error object workaround to ensure that somebody gets notified when an exception is found.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events