JavaScript Step error Handling
If you are familiar with the error features of the kettle conversion, you may want to know how to use it in JavaScript steps. Steps to support the error mechanism the user interface mechanism is the same, right-click on the JavaScript step, select "Define error Handling" To enable error handling and configure. The JavaScript code can identify the error lines and forward them to the configured error handling steps, which require the following several parameters by using the Puterror () method of the _step_ object:
1) Rowmetainterface Object Description Row structure
2) the current error line
3) Number of errors detected on this line
4) Error description string (Error message)
5) field name (string) that caused the error
6) Error code (string)
Typically, the original, unmodified input line is passed to the error-handling step. As a result, the first two parameters are typically specified as Getinputrowmeta () and row. The other parameters depend on how you want to describe the error you are encountering. The JavaScript step defines the error handling configuration that can be configured for those field output to the error handling step.
The example of this conversion first generates a random string. For illustrative purposes, the JavaScript step determines that the previously generated characters are missing the letters ' a ' and ' K ', and each missing letter produces an error.
The JavaScript steps contain the following code:
Varshould_error_on_a= (Value.indexof ("a") = =-1)? 1:0;varshould_error_on_k= (Value.indexof ("k") = =-1)? 1:0; try{if (should_error_on_a== 1 && should_error_on_k = = 1) {throw{message: "Value must Contai N ' a ' and ' K ' ", Nr_errors:2, Field:" Value ", Errcode:" Err:003 "}} elseif (Sho uld_error_on_a== 1) {throw{message: "Value must contain ' a '", Nr_errors:1, field: " Value ", Errcode:" err:001 "}} elseif (should_error_on_k== 1) {throw{message:" Val UE must contain ' K ' ", Nr_errors:1, Field:" Value ", Errcode:" Err:002 "}}//co Ntinue Normally, passing the row on to the next step trans_status= continue_transformation; }catch (e) {//divert The current row to the error step and do not pass anything to Thenext step _step_.puterror (Geti Nputrowmeta (), row, E.nr_errors, E.message, E.field, E.errcode); Trans_status= skip_transformation;}
JavaScript step error handling in kettle