pentaho/pentaho-kettle · error · KettleValueException

ScriptValuesMod.Log.JavascriptError

Error message

ScriptValuesMod.Log.JavascriptError

What it means

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.).

Solutions

  1. Read the 'Caused by' JavaScriptException for the script line and error message
  2. Fix the runtime error in the transform script (undefined variable, wrong API usage)
  3. Verify all fields referenced in the script exist in the incoming row (check upstream steps)
  4. Add try-catch or null checks inside the script around risky operations
  5. Use logMinimal/logBasic in the script to trace values before the failing statement

Example fix

// before: runtime ReferenceError when field is missing
var total = price * qty;
// after: defensive checks in script
var total = ( price != null && qty != null ) ? price * qty : 0;
Defensive patterns

Strategy: try-catch

Validate before calling

// Guard referenced fields exist before using them in the script
if ( typeof price == "undefined" || typeof qty == "undefined" ) {
  throw "Required fields missing from row";
}

Type guard

function hasField(scope, name) {
  return typeof scope[name] !== "undefined" && scope[name] !== null;
}

Try / catch

try {
  processRow();
} catch ( KettleValueException e ) {
  Throwable c = e.getCause();
  logError( "Script runtime error: " + ( c != null ? c.getMessage() : e.getMessage() ), e );
  putError( ... ); // send row to error stream
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/01c2901fb2e127c0. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesMod.java:469

            bRC = false;
            break;
          case ERROR_TRANSFORMATION:
            if ( data.cx != null ) {
              Context.exit();
            }
            setErrors( 1 );
            stopAll();
            bRC = false;
            break;
          default:
            break;
        }

        // TODO: kick this "ERROR handling" junk out now that we have solid error handling in place.
        //
      }
    } catch ( Exception e ) {
      throw new KettleValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.JavascriptError" ), e );
    }
    return bRC;
  }

  public Object getValueFromJScript( Object result, int i ) throws KettleValueException {
    String fieldName = meta.getFieldname()[ i ];
    if ( !Utils.isEmpty( fieldName ) ) {
      // res.setName(meta.getRename()[i]);
      // res.setType(meta.getType()[i]);

      try {
        return ( result == null ) ? null
          : JavaScriptUtils.convertFromJs( result, meta.getType()[ i ], fieldName );
      } catch ( Exception e ) {
        throw new KettleValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.JavascriptError" ), e );
      }
    } else {
      throw new KettleValueException( "No name was specified for result value #" + ( i + 1 ) );

View on GitHub (pinned to f3058517a1)