{"record":{"id":"01c2901fb2e127c0","repo":"pentaho/pentaho-kettle","slug":"scriptvaluesmod-log-javascripterror","errorCode":null,"errorMessage":"ScriptValuesMod.Log.JavascriptError","messagePattern":"ScriptValuesMod\\.Log\\.JavascriptError","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java","lineNumber":469,"sourceCode":"            bRC = false;\n            break;\n          case ERROR_TRANSFORMATION:\n            if ( data.cx != null ) {\n              Context.exit();\n            }\n            setErrors( 1 );\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 solid error handling in place.\n        //\n      }\n    } catch ( Exception e ) {\n      throw new KettleValueException( BaseMessages.getString( PKG, \"ScriptValuesMod.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, \"ScriptValuesMod.Log.JavascriptError\" ), e );\n      }\n    } else {\n      throw new KettleValueException( \"No name was specified for result value #\" + ( i + 1 ) );","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java#L451-L487","documentation":"Top-level wrapper thrown by ScriptValuesMod.addValues() when any Exception occurs while executing the user script or extracting its result values. The whole row-level script execution block is wrapped in try-catch and rethrown as a KettleValueException with 'Javascript error'. The cause contains the actual script runtime error (Rhino JavaScriptException, etc.).","triggerScenarios":"data.script.exec(data.cx, data.scope) or result-value extraction throws while processing a row — e.g. runtime ReferenceError, TypeError, or a Java exception thrown from script code — inside addValues() called by processRow.","commonSituations":"Calling undefined functions/fields in the script, divide by null, invoking Java APIs with wrong arguments, script using a field name that upstream no longer provides, or throw statements in user code.","solutions":["Read the 'Caused by' JavaScriptException for the script line and error message","Fix the runtime error in the transform script (undefined variable, wrong API usage)","Verify all fields referenced in the script exist in the incoming row (check upstream steps)","Add try-catch or null checks inside the script around risky operations","Use logMinimal/logBasic in the script to trace values before the failing statement"],"exampleFix":"// before: runtime ReferenceError when field is missing\nvar total = price * qty;\n// after: defensive checks in script\nvar total = ( price != null && qty != null ) ? price * qty : 0;","handlingStrategy":"try-catch","validationCode":"// Guard referenced fields exist before using them in the script\nif ( typeof price == \"undefined\" || typeof qty == \"undefined\" ) {\n  throw \"Required fields missing from row\";\n}","typeGuard":"function hasField(scope, name) {\n  return typeof scope[name] !== \"undefined\" && scope[name] !== null;\n}","tryCatchPattern":"try {\n  processRow();\n} catch ( KettleValueException e ) {\n  Throwable c = e.getCause();\n  logError( \"Script runtime error: \" + ( c != null ? c.getMessage() : e.getMessage() ), e );\n  putError( ... ); // send row to error stream\n}","preventionTips":["Null-check all field values inside the script before arithmetic","Confirm field names referenced in the script match upstream output exactly","Wrap risky script sections in script-level try-catch and log instead of throwing"],"tags":["javascript","rhino","runtime-error","script-execution"],"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"}