{"record":{"id":"8a47e6a12940681b","repo":"pentaho/pentaho-kettle","slug":"script-log-javascripterror","errorCode":"Script.Log.JavascriptError","errorMessage":"Script.Log.JavascriptError","messagePattern":"Script\\.Log\\.JavascriptError","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java","lineNumber":386,"sourceCode":"            break;\n          case ERROR_TRANSFORMATION:\n            if ( data.cx != null ) {\n              // Context.exit(); TODO AKRETION not sure\n              setErrors( 1 );\n            }\n            stopAll();\n            bRC = false;\n            break;\n          default:\n            break;\n        }\n\n        // TODO: kick this \"ERROR handling\" junk out now that we have\n        // solid error handling in place.\n        //\n      }\n    } catch ( ScriptException e ) {\n      throw new KettleValueException( BaseMessages.getString( PKG, \"Script.Log.JavascriptError\" ), e );\n    }\n    return bRC;\n  }\n\n  public Object getValueFromJScript( Object result, int i ) throws KettleValueException {\n    String fieldName = meta.getFieldname()[ i ];\n    if ( !Utils.isEmpty( fieldName ) ) {\n      // res.setName(meta.getRename()[i]);\n      // res.setType(meta.getType()[i]);\n\n      try {\n        return ( result == null ) ? null\n          : JavaScriptUtils.convertFromJs( result, meta.getType()[ i ], fieldName );\n      } catch ( Exception e ) {\n        throw new KettleValueException( BaseMessages.getString( PKG, \"Script.Log.JavascriptError\" ), e );\n      }\n    } else {\n      throw new KettleValueException( \"No name was specified for result value #\" + ( i + 1 ) );","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/Script.java#L368-L404","documentation":"Thrown in Script.addValues when the main transform script's evaluation throws a javax.script.ScriptException. After the scope is prepared, data.script.eval(data.scope) runs the user's JavaScript; any error raised inside the script (runtime error, thrown JS exception, undefined function call) surfaces as this KettleValueException. This is the standard failure path for buggy transform scripts.","triggerScenarios":"addValues (called from processRow): data.script.eval(data.scope) throws a ScriptException — e.g. calling an undefined function, accessing a property of an undefined variable, or the script explicitly throwing — on any row being processed.","commonSituations":"Scripts referencing fields not present on some rows (null handling mistakes); calling functions that don't exist in this engine (Rhino vs Nashorn differences); division by zero or type coercion errors on dirty data; using Java imports unavailable in the sandbox.","solutions":["Read the wrapped ScriptException's line number/message to find the failing script line.","Add null/undefined checks around field access in the script.","Guard row-dependent logic with conditionals so rows missing fields don't crash the run.","Use the step's Test script feature with sample data reproducing the failing row."],"exampleFix":"// before\nvar v = strField.toUpperCase();\n// after\nvar v = (strField != null) ? strField.toUpperCase() : null;","handlingStrategy":"try-catch","validationCode":"// defensive script skeleton to run before trusting rows:\n// if (typeof someField == \"undefined\" || someField == null) { someField = defaultValue; }","typeGuard":"function isDefined(v) { return typeof v !== \"undefined\" && v !== null; }","tryCatchPattern":"try {\n  step.processRow();\n} catch (KettleValueException e) {\n  if (e.getMessage().contains(\"JavascriptError\") || e.getCause() instanceof ScriptException) {\n    logError(\"Script runtime error: \" + e.getCause().getMessage());\n    putError(...); // route row to error handling instead of failing\n  } else { throw e; }\n}","preventionTips":["Guard every field access for null/undefined.","Do not rely on engine-specific functions (check Rhino vs Nashorn support).","Enable step error handling to divert bad rows instead of aborting.","Test the script with edge-case data (nulls, empty strings, zero)."],"tags":["kettle","javascript","runtime-error","script-eval"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}