Lot’s of fun doing this one. Last fall at the KNIME UGM in Austin, i learned this technique from @alinebessa in the course that she taught. In practice, i have been using it ever since in my real world applications and i can say it really makes them very robust.
For this challenge, I actually struggled to create an example workflow that threw the proper error. Also what was very exciting is that i finally installed v5.1 of the KNIME AP and for the first time used the new UI. it is gorgeous!!! But i admit, when i had trouble i reverted to the old UI to get things done…
To the solution:
The Orange Workflow. A hypothetical workflow that is not intended to solve any problem, but has operations i use all the time. This workflow starts with a list of produce being purchased at the grocery store. Each row is a different customer and each column is contains a separate item of produce for that customer. The rows are then looped over and inside the loop, it is necessary to use each customers list of produce to rename the rowID (again… this is totally hypothetical). An action is the added with the java snippet node. When the loop is finished, you have a final table with the list of items and the action. Here are the before and after tables:
The Green Workflow. In this modification, customer = Row2 decides to buy two bananas.
This creates a problem later in the original workflow because you cannot have two rows with the same RowID. This issue throws and error that we deal with using the Try-Catch approach.
On the top stream of the Try-Catch, the RowID node throws the error and so the error-handling bottom stream deals with the issue by appending the row index to the duplicate entries in order to uniquify them. The error is circumvented and the loop can continue until execution is complete.
The Blue Workflow. This last version handles the error logging. I dont normally do this so there could be a better way for some parts. After the Try-Catch segment, i added a metanode that adds a few fields using Java Snippet (Simple) nodes, in part, via flow variables created by an Extract Context Properties node. Also included were Java Snippet (Simple) nodes for the Failing Node and Error Message provided by the Catch Node. Be sure to select “always populate error variable” in the Catch configuration dialog, otherwise the Java Snippet (simple) node will throw an error (Fun Fact- you can overcome this error using a second Try-Catch sequence )
Finally, I add a timestamp at the end of the workflow to indicate when the workflow finished… since it executes so fast, i inserted a Wait node set to a 5 sec delay just so the time stamps were actually different.
Finally we end with a csv writer node as requested. In order to properly log new entries on subserquent execution, be sure to select append in the CSV Writer node configiration dialog.
Hope you had as much fun as i did… if anyone sees a better way to do any part, please let me know. I am always excited to learn from you all.