Blog

Managed File Transfer and Network Solutions

How to Ignore Specific Errors in Exception Handling | JSCAPE

Posted by John Carl Villanueva on Sun, Apr 05, 2020 @ 04:35 PM

In a previous post, we taught you how to set up triggers that catch and handle trigger errors thrown by other triggers. Now, earlier this week, we received a query from a customer who had this kind of trigger but wanted to ignore a particular trigger event. That is, they didn't want their error handling trigger to execute its succeeding action(s) if the error thrown was a certain type of error. Here's one way to do it. 

We'd like to illustrate this in an example but if you want to know the answer straightaway and just skip the example, here it is in a nutshell. 

Watch the video 

Would you prefer to watch a video version of this tutorial instead? You can play the video below. Otherwise, just skip it if you wish to continue reading.

As you probably know by now, JSCAPE MFT Server triggers have one or more trigger actions. It's actually from these trigger actions that most errors originate. Now, when a trigger action fails, a Trigger Error event is raised. And each of these Trigger Error events are accompanied by a set of properties, each represented by variables. 

One of these variables is ActionMessage. This variable holds the error message received when executing the trigger action. Note that this is different from the optional TriggerErrorMessage property. For example, when the SFTP File Download trigger action fails as a result of a missing remote file, which is the file that the action is supposed to download, the action will generate a message that says "Server error: Invalid path" and store this message in the ActionMessage variable.

So, if you want to ignore all errors thrown by the SFTP File Download action caused by missing remote files, you can therefore add a trigger condition in your error handling trigger that ignores this particular Action message. 

To do that, just add an expression similar to this:

ActionMessage !# "Server error: Invalid path"

The !# operator means 'Does not contain'

So, this trigger will only execute its accompanying trigger actions if the ActionMessage of the trigger error event DOES NOT CONTAIN the string "Server error: Invalid path". If the ActionMessage contains "Server error: Invalid path", then the error will be ignored and the trigger will NOT execute.

If you want to see an example illustrating how this works, read on.

Example 

I have here a trigger named 'sftp pick up'. 

sftp pick up trigger edit 1

sftp pick up trigger step 2 of 3

 

This trigger downloads a file from an SFTP server. 

 

sftp pick up trigger step 3 of 3

 

sftp file download action 1

 

As you can see, the file it's supposed to download is named file.txt and it's located in the virtual root path of the account named user1.

 

sftp file download action 2

 

Here's that file as seen from the file system. Notice that there's no other file in the file's directory.

 

file in directory mac-1

 

If we run the trigger...

 

run sftp pick up

 

... and check the running domain logs, we should be able to trace the 'sftp pick up' trigger's entire trigger execution process, from the moment the trigger was queued down to the moment the trigger was completed. We can even see the part where the file.txt was downloaded. 

 

sftp pick up trigger execution in logs

 

Let's now head back into the 'sftp pick up' trigger's action parameters and make some changes. Let's change the name file.txt to file1.txt and leave everything as is. Because there's no file1.txt in this remote path, this trigger should fail. 

 

modified remote file in sftp file download

 

So, if we run this trigger again ...

 

run sftp pick up

 

... and check the logs, we should see the same trigger execution process. But this time, it already includes a couple of entries indicating an error. As you can see, the SftpFileDownloadAction failed and it generated a message that said something like: "Server error: Invalid path..."

We'll use that message in a short while.

 

sftp pick up trigger execution in logs with error

 

But first, let's go back to the Triggers module. You might not have noticed it earlier, but I have another trigger named 'error detector'. 

 

error detector

 

This trigger is an error handling trigger, so it listens to the Trigger Error event type. This was previously disabled, so let's enable it now. 

 

enable error detector

 

If we look at the trigger conditions dialog, we see that this trigger only responds to errors thrown by the 'sftp pick up' trigger whose ActionMessage contains the string "Server error: invalid path".

 

error detector trigger conditions

 

Since this is only an example, I just set this trigger to generate the following message on system out. 

 

system out in error detector trigger

 

Let's now see this trigger in action. Let's run the 'sftp pick up' trigger again.

 

run sftp pick up with error

 

So, if we review the logs, we see that:

  • The 'sftp pick up' trigger was able to run;
  • Its 'SFTP file download' action failed; and then, after that,
  • The 'error detector' trigger kicked in

 

log with sftp pick up and error detector

 

And if we scroll down further, we'll see that, because the conditions of the 'error detector' trigger were satisfied, its subsequent trigger action, a SystemOut action, printed the message specified earlier.

In a production environment, the action might be different. It might be an Append File action that prints details of the error in a separate error log file or perhaps a Send Email action that sends out email alerts to a server administrator. 

 

logs showing error detector trigger details

 

Alright, that's well and good but this is not the kind of example we came here for. What we wanted was a trigger that would ignore a certain type of error. So, let's proceed and do that. Let's modify this trigger so that it will instead ignore errors coming from the 'sftp pick up' trigger that contain the string "Server error: Invalid path" in its ActionMessage. If this string is found, then the trigger will not execute.

There are a number of possible errors that can be thrown by the 'sftp pick up' trigger's SFTP File Download action, but what I can think of right now is when one of the connection settings is wrong; in which case, the trigger action will be unable to connect and the connection attempt will timeout. 

So, let's edit the 'sftp pick up' trigger and change some connection settings in its SFTP File Download action. Let's just change port number to 23. Since the remote SFTP service is listening on port 22, this trigger action will be unable to connect and eventually timeout. 

 

wrong port number in sftp pick up

 

If you're testing this out yourself, you might want to reduce this trigger action's timeout value to, say, 5 seconds. That way, you won't have to wait too long for the connection attempt to timeout. 

 

timeout of sftp file download action

 

After saving those changes, we'll now want to modify our 'error detector' trigger.

 

edit error detector trigger

 

We'll want it to ignore only those errors that contain the string "Server error: Invalid path" in its ActionMessage. To do that, we just change the # (contains) operator to the !# (not contains) operator. 

So, now, the trigger condition that you see on the screen now says:

This trigger should only respond to trigger errors coming from the trigger 'sftp pick up' if their ActionMessage does not contain the string "Server error: Invalid path".

 

edit error detector trigger condition

 

To avoid any confusion in the ActionMessage entries in the logs, let's just remove the part that says "file1.txt not found!!!!". So, all that's going to be printed out in the logs is:

Action message: [the value of the ActionMessage variable]

 

edit system out action

 

So, once again, let's fire up the 'sftp pick up' trigger.

You might want to wait at least 5 seconds before checking the logs to give the trigger action's connection attempt to time out. 

 

run sftp pick up with error

 

Once those 5 seconds elapse, you can then check the running log. You'll see that both the 'sftp pick up' and the 'error detector' triggers have fired. And then, once you check the log entries for the 'error detector' trigger, you should see the SystemOutAction's action message saying: "Action message: Connection refused".

So what exactly happened here? Because the ActionMessage wasn't "Server error: Invalid path", the 'error detector' trigger simply proceeded to execute its SystemOut trigger action.

 

log connection refused

 

So, what would happen if the ActionMessage is "Server error: Invalid path"? Let's find out.

Let's go back one more time to the 'sftp pick up' trigger...

 

edit sftp pick up one more time

 

... and let's change these settings again. Let's bring back the port number to 22 and the remote file to file1.txt. This means, this trigger will be able to connect but it will still fail because it won't be able to find the remote file it's supposed to download. Remember that the correct file name is file.txt and we're attempting to download a file1.txt.

 

sftp file download parameters new

 

So, if we run this trigger one last time...

 

run sftp pick up with error

 

... and then check the logs, we should see that, while the 'sftp pick up' trigger runs and fails, the 'error detector' trigger does not run at all. 

 

sfpt pick up runs and fails-1

 

That's it. Now you know how to configure an error handling trigger to ignore specific errors. 

Would you like to try this out yourself? Download the FREE, fully-functional Starter Edition of JSCAPE MFT Server now.

Download Now

Topics: JSCAPE MFT Server, Managed File Transfer, Tutorials, Triggers