Hitachi Vantara Pentaho Community Forums
Results 1 to 4 of 4

Thread: JavaScript step error handling

  1. #1
    Join Date
    Jul 2014
    Posts
    10

    Default JavaScript step error handling

    Hello,
    I'm having some issues on error handling.
    I'm trying to do a fine-grained validation on data input and I've written some javascript code to do it.

    Code:
    // validation
    
    function isBlank(p) {
    	if ( typeof p == "object"){
    		if ( p ) 
    			return false;
    		else
    			return true;
    	}
       	return !(!!p && !(p.trim().length === 0));
    }
    
    
    try{
    	if ( isBlank(NUMERO_PRATICA))
    		throw {
                message: "NUMERO_PRATICA should not be empty",
                nr_errors: 1,
                field: "value",
                errcode: "ERR:002"
            }
    	
    
    
    	trans_Status = CONTINUE_TRANSFORMATION;
    	
    }
    catch(e){
    	Alert("yo");
    	_step_.putError(getInputRowMeta(), row, e.nr_errors, e.message, e.field, e.errcode);
        trans_Status = SKIP_TRANSFORMATION;
    }
    Now, this is my Transformation:

    Name:  error.jpg
Views: 996
Size:  14.3 KB

    To sum it up: I select some rows from a table (and they're coming up just fine), do the validation you can see in the code up and if it's wrong throw an error.

    Ideally, I'd like the Transformation work like this:
    Every record you find faulty, you put it in the log and update the selected record (so that another service will manage it) and keep working the other (hopefully/ correct records.

    Is it possible?

    I've read everything I could online on pentaho error handling but I'm facing a wall:
    The errors goes correctly on the log BUT the step "convert Json" also goes in error since it's trying to convert null values.
    Also, how can I put the error message I'm throwing up in the javascript code?

    Thanks in advance,
    Massimo.

  2. #2
    Join Date
    Jul 2014
    Posts
    10

    Default

    nevermind, managed to fix it, for those wondering:

    Replaced the default script step with the open source one -> this fixed the other steps from sucking the output from the error...
    Found this: http://type-exit.org/adventures-with...vascript-step/ -> this fixed the error of my throw erorr message being displayed by the error log.
    Just download the example and see for youself the right-click->"manage error definition".
    The important part was: "error_description" field value in the "name of the field..."

  3. #3
    Join Date
    Jul 2014
    Posts
    10

    Default

    I'm sorry but it seems to me that the component "JSON Output" doesn't work fine with the java component and the error handling bundled with it.

    After I restarted Kettle and tried it again today, it kept giving me the same error:

    Code:
    2014/07/21 14:31:47 - Json output.0 - ERROR (version 5.1.0.0, build 1 from 2014-06-19_19-02-57 by buildguy) : Errore inatteso2014/07/21 14:31:47 - Json output.0 - ERROR (version 5.1.0.0, build 1 from 2014-06-19_19-02-57 by buildguy) : org.pentaho.di.core.exception.KettleStepException: 
    2014/07/21 14:31:47 - Json output.0 - Unable to clone row for metadata : null
    2014/07/21 14:31:47 - Json output.0 -  at java.lang.Thread.run (Thread.java:662)
    2014/07/21 14:31:47 - Json output.0 -  at org.pentaho.di.trans.step.RunThread.run (RunThread.java:62)
    2014/07/21 14:31:47 - Json output.0 -  at org.pentaho.di.trans.steps.jsonoutput.JsonOutput.processRow (JsonOutput.java:181)
    2014/07/21 14:31:47 - Json output.0 -  at org.pentaho.di.trans.steps.jsonoutput.JsonOutput.outPutRow (JsonOutput.java:231)
    2014/07/21 14:31:47 - Json output.0 -  at org.pentaho.di.trans.step.BaseStep.putRow (BaseStep.java:1225)
    2014/07/21 14:31:47 - Json output.0 -  at org.pentaho.di.ui.spoon.trans.TransPreviewDelegate$3.rowWrittenEvent (TransPreviewDelegate.java:479)
    2014/07/21 14:31:47 - Json output.0 - 
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.ui.spoon.trans.TransPreviewDelegate$3.rowWrittenEvent(TransPreviewDelegate.java:481)
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.trans.step.BaseStep.putRow(BaseStep.java:1225)
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.trans.steps.jsonoutput.JsonOutput.outPutRow(JsonOutput.java:231)
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.trans.steps.jsonoutput.JsonOutput.processRow(JsonOutput.java:181)
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
    2014/07/21 14:31:47 - Json output.0 - 	at java.lang.Thread.run(Thread.java:662)
    2014/07/21 14:31:47 - Json output.0 - Caused by: java.lang.NullPointerException
    2014/07/21 14:31:47 - Json output.0 - 	at org.pentaho.di.ui.spoon.trans.TransPreviewDelegate$3.rowWrittenEvent(TransPreviewDelegate.java:479)
    2014/07/21 14:31:47 - Json output.0 - 	... 5 more
    I replaced it by a Javascript custom script that builds the JSON manually and now it works without any problem!

    Can someone take a look at this and tell me I'm insane?

    Thanks, please

  4. #4
    Join Date
    Apr 2008
    Posts
    1,771

    Default

    If you think that the JSON Output step has a bug, please test it and report it in JIRA:
    http://jira.pentaho.com
    -- Mick --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.