Skip to content

Handling Errors in a Project

Looking for an example project to get you started?
  • Support_Sai Offline

Handling Errors in a Project

Post by Support_Sai »

When creating a project, one can define the action to take when there is an error in a Task, Module or the Project. For example, you want to create a project to FTP a file to a remote server, and if the project fails for any reason, you want to send an email to one or more users. The example project below demonstrates how this can be achieved:

Code: Select all

<project name="Error Handling Example" mainModule="Main" version="1.0" onError="call:Send Error Notification">

	<module name="Main">
		<ftp resourceId="My FTP Server">
			<put sourceFile="/myfile.txt" destinationDir="/targetdir" />
		</ftp>
	</module>

	<module name="Send Error Notification">
		<sendEmail resourceId="My Mail Server" toList="[email protected], [email protected]">
			<from address="[email protected]" />
			<message>
				<![CDATA[The following error occurred when running the project, ${system.project.name}: 

${system.job.error}]]>
			</message>
		</sendEmail>

		<raiseError>
			<message>The following error occurred when running the project, ${system.project.name}: 

${system.job.error}</message>
		</raiseError>

	</module>

</project>
In the above project, we defined On Error at the project level to call a module named Send Error Notification. This can be setup under the Advanced tab of the project. Then in the Send Error Notification module, we have a sendEmail task for sending an email. After the sendEmail task, we also have a raiseError task to raise an error with a custom message.

Since we caught the error with our Send Error Notification module the job will always be marked as successful unless we use the raiseError task.

The error handling can also be customized at a specific module level, or at a specific task level, by defining the On Error attribute on the module or task. This option can be found under the Advanced tab of every module and task.

Note:
If you are using GoAnywhere's scheduler to run a project, the Scheduler has built-in email notification when the project completes normally or with an error. We recommend that you use this option if all you want to do is get email notifications upon errors.