PhixFlow Help
Handling operational errors
By the end of this chapter you will be able to:
- Use the try() function
- Use the jumpTo() function
- Handling and reporting errors
- Sending messages to the Console log with error(), warning() and info()
Using try()
A file containing details of customer transactions can be found in the input files, at:
…\inputData\CustomerTransactions\Customer Transactions.xlsx
This file contains a list of transactions on an account. The dates should be provided in the format dd-MMM-yy, e.g. 12-May-08. But you will see in the data that many dates in the file do not follow this format.
- Create a File Collector and a Stream to read this data into PhixFlow
- Add an attribute to the Stream with Type Date, to attempt to convert the transaction dates to a true date (using the function toDate())
- Around the date conversion use try(), and if the conversion fails capture the error in a local variable (e.g. $error)
- Add another attribute to print out this error
- Run the stream to see the results
Using jumpTo()
- Add an attribute to your stream to work out the age of each transaction – use the dateDiff() function
There is no point in doing this (and in fact the call to dateDiff() will fail) if the previous conversion of the transaction date failed
- Edit the call to the try() function so that, in the event of failing to convert the transaction date, you jump straight to an Error attribute without attempting to work out the age of the transaction
Handling and reporting errors
You will now load a new list of account numbers, and enrich this with, for each account, the post code and the phone number:
- Drag the streams
- MC Error Account List
- MC Error Phone Numbers
- MC Error Post Codes
onto your model - these have been preconfigured to read in data from an external database
- Create a new stream to copy the data from MC Error Account List
- Add lookup pipes into this new stream from MC Error Phone Numbers and MC Error Post Codes to enrich the account list with the phone number and post code for each account
- In some cases, no post code or phone number will be found - for each lookup check to see if a value was found – if not, add an error to a list
- Add an attribute to the stream to print out all errors found while processing each record
Sending messages to the Console
- Add into your error traps calls to error() – to send an error messages to the Console
- Try and use the same error message to send as you added to the list of errors
- Then try this with warning() and info() – note the difference in how these appear in the Console
Please let us know if we could improve this page feedback@phixflow.com