Question

Workflow Error Handling

  • 10 February 2021
  • 4 replies
  • 77 views

Userlevel 1
Badge +3

Hi All

I’m trying to come up with a kind a universal Error Handling for Workflows, in particular for ExecuteCommand Activities. Often enough they throw an exitCode > 0 and some commandOutput that may help the User.

BUT then there are the times where exitCode is 0 but the outputXml states an error-condition. Tried to check and handle that via OnComplete Scripts.This is where I am stuck. Sometimes the response is generic and has an errorCode and errorString Element to parse, sometimes the errorString is missing, sometimes errorCode is 0 but an warningCode Element is added, but that isn’t returned all the time. Sometimes it’s a longer App_***Response Reply with the issues tucked in somewhere.

Anybody know of a generic way to parse through all possible scenarios (mentioned or unmentioned) to catch issues right away, terminate execution and return useful consistent error Messages to User?

Thanks,

Stefan


4 replies

Userlevel 1
Badge

You can use xpath queries (such as //errorCode, //errorMessage, //warningCode) in the onComplete script to check for these values in the response xml.

A sample way of doing this is

XML outputXml = utils.parseXml(xpath:{/workflow/Execute_1/outputXml});

if (outputXml != null) {

  String errorCode = outputXml.getText("//errorCode");

  String errorMessage = outputXml.getText("//errorMessage");

  String warningCode = outputXml.getText("//warningCode");

}

 

if these are null then they didn’t exist in the outptuXml.

 

This works well if these are elements in the response which I believe is most of the case now a days but if you see any responses with these come across as attributes then your query would need to change to use the @ symbol

String errorCode = outputXml.getText("//@errorCode");

String errorMessage = outputXml.getText("//@errorMessage");

String warningCode = outputXml.getText("//@warningCode");

 

You could always combine them and make a big script to check for all cases

String errorCodeE = outputXml.getText("//@errorCode");

String errorCodeA = outputXml.getText("//@errorCode");

String errorCode = errorCodeA != null ? errorCodeA : errorCodeE

 

 

Userlevel 1
Badge +3

Hi Chris

Tried something similar to your first recommendation, after finding samples in BOL don’t really work. That works well when all those Attributes exist. If they don’t, or have different Attribute-Names, it gets complicated. Like I know errorString but can’t remember seeing errorMessage, maybe that’s something new in FR20+.

Current working prototype below. Open for recommendations on how to make it cover more conditions and less Null-Pointer-Exception-y (I’m a Java Noob)

if(activity.exitCode == 0)
{
logger.info("in EC 0");
if (activity.outputXml != null)
{
XML xml = utils.parseXml(activity.outputXml);
String errorCode = xml.getText("//errorCode");
String warningCode = xml.getText("//warningCode");
String errorString = xml.getText("//errorString");
logger.warn("error: "+errorCode);
logger.warn("warning: "+warningCode);
logger.warn("string: "+errorString);

if (errorCode != null && warningCode != null && (errorCode > 0 || warningCode > 0))
{
logger.info("in xml processing");
activity.exitCode = Integer.parseInt(errorCode);
activity.commandOutput = errorString;
workflow.setFailed("Error ["+activity.exitCode+"] : "+activity.commandOutput);
}
}

}

Thanks,

Stefan

 

Userlevel 5
Badge +10

Open for recommendations on how to make it cover more conditions and less Null-Pointer-Exception-y (I’m a Java Noob)

 

 

:joy:

Userlevel 1
Badge

The only thing I’d change here is with this if statement

errorCode != null && warningCode != null

You may want to use an || otherwise both of these would have to be not null just to get the errorCode

If you run across this not working for a particular response, let me know and we can adjust it to handle it as well.

 

Reply