Page History
Table of Contents |
---|
Error Handling
JS7 - JavaScript Jobs apply error handling at job level as offered by the JavaScript language.
For error handling at workflow level using JS7 - Workflow Instructions see JS7 - How to apply error handling.
Download workflow implementing JavaScript error handling (upload .json): pdJavaScriptErrorHandling.workflow.json
Terminating Job successfully
There are no specifics for successful termination of a JavaScript job:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { // do some stuff return; // ... } } |
Explanation:
- No specific measures apply. As in any As for every JavaScript function the
return
statement can be used to leave theprocessOrder()
method prematurely. - If the
return
statement is not used then the job terminates successfully when leaving theprocessOrder()
method.
Terminating Job successfully with warning due to return code
JavaScript Jobs can be configured to continue in case of warnings and to send a JS7 - NotificationNotifications:
- JavaScript Jobs can be configured to expect consider a number of return codes that are considered raise warnings.
- Such Any return codes will not fail the job but will result in a notification if specified with the job configuration.
The implementation of the a job that specifies a return code looks like this:
...
- The
getLogger().warn()
method creates log output that qualifies as a warning. - The
getOutcome().setReturnCode()
method is used to specify a return code:- Setting the return code in a JavaScript job Job does not raise an error.
- Return codes can be checked in a subsequent job or JS7 - If Instruction.
- If the job configuration specifies one or more Return Codes on Warning and if the job's return code matches one of the values then a notification is created. Otherwise the job will terminate successfully without a warning.
- For details see JS7 - Job API.
...
Optionally notifications for warnings are sent by mail if configured by JS7 - Notification- Notifications.
Terminating Job successfully with warning due to output to stderr
This scenario applies to a situation when an unsolicited error occurs that results in output to to the stderr channel, for details see JS7 - How to detect job errors and warnings
- No exception is raised in JavaScript, but some statement fails and writes to stderr. In this situation the job continues and might terminate successfully.
- The JS7 - Job Instruction offers the Warn on output to stderr option: if any output in the stderr channel is detected then the job is considered to terminate with warnings.
In the Configuration->Inventory view users specify the related option from the Job Options tab like this:
A job that writes output to the stderr channel can be implemented like this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job {
processOrder(js7Step) {
// do some stuff
js7Step.getLogger().error('some error occurred');
return;
}
} |
Explanation:
- No error is raised in this example. Instead the
getLogger().error()
method is used to write output to stderr. - Similarly any other JavaScript statements can create output in the stderr channel.
Terminating Job with error
The typical error handling for JavaScript applies:
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { try { js7Step.getLogger().info( '.. try: do some stuff') throw 'error occurred, exiting job'; } catch (e) { js7Step.getLogger().info('.. catch: do some error handling') throw e; } finally { js7Step.getLogger().info('.. finally: do some cleanup such as closing database connections') } } } |
Terminating Job with error due to output to stderr
This scenario applies to a situation when an unsolicited error occurs that results in output to to the stderr channel, for details see JS7 - How to detect job errors and warnings
- No exception is raised in JavaScript, but some statement fails and writes to stderr. In this situation the job continues and might terminate successfully.
- The JS7 - Job Instruction offers the Fail on output to stderr option: if any output in the stderr channel is detected then the job is considered being failed.
In the Configuration->Inventory view users specify the related option from the Job Options tab like this:
A job that writes output to the stderr channel can be implemented like this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
class JS7Job extends js7.Job { processOrder(js7Step) { // do some stuff js7Step.getLogger().error('some error occurred'); return; } } |
Explanation:
- No error is raised in this example. Instead the
getLogger().error()
method is used to write output to stderr. - Similarly any other JavaScript statements can create output in the stderr channel.