pentaho/pentaho-kettle · error · KettleValueException

ScriptValuesMod.Log.CouldNotAddDefaultFunctions

Error message

ScriptValuesMod.Log.CouldNotAddDefaultFunctions

What it means

After attaching user scripts, addValues() exposes Pentaho's built-in helper functions by calling Context.javaToJS(ScriptValuesAddedFunctions.class, ...) and defineFunctionProperties(jsFunctionList, ...) on the scope; any Exception is rethrown as KettleValueException with message ScriptValuesMod.Log.CouldNotAddDefaultFunctions. This indicates the standard script function library could not be registered, so built-in functions would be unavailable.

Solutions

  1. Check the cause stack trace ('ex') in the log to see whether the failure is in javaToJS or defineFunctionProperties.
  2. Verify the rhino jar on the classpath matches the one shipped with your Pentaho version; remove any manually upgraded rhino jar.
  3. Reinstall/refresh the scriptvalues_mod plugin so ScriptValuesAddedFunctions matches the step's expected version.
  4. Confirm data.scope comes from cx.initStandardObjects (a ScriptableObject) and was not replaced by custom scope code.
  5. If you patched ScriptValuesAddedFunctions, ensure every method listed in jsFunctionList keeps the exact static signature Rhino requires (public static, Context/Scriptable args).

Example fix

// before: custom newer rhino.jar placed in lib/ overriding Pentaho's bundled version
lib/rhino-1.7.15-custom.jar
// after: restore the bundled version
lib/rhino-<pentaho-bundled-version>.jar
Defensive patterns

Strategy: try-catch

Validate before calling

// Java, sanity-check the script environment before executing the transformation
if (!(data.scope instanceof ScriptableObject))
  throw new IllegalStateException("JS scope is not a ScriptableObject; initStandardObjects failed");
Class.forName("org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions");
// also verify no conflicting rhino jar: check ProtectionDomain of Context class

Try / catch

try {
  transformation.execute(params);
} catch (KettleValueException e) {
  if (e.getMessage().contains("CouldNotAddDefaultFunctions")) {
    log.error("Default function registration failed: " + e.getCause(), e.getCause());
    // check rhino jar version / plugin install, then retry
  } else { throw e; }
}

Prevention

When it happens

Trigger: Context.javaToJS on ScriptValuesAddedFunctions.class or ((ScriptableObject) data.scope).defineFunctionProperties(ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class, DONTENUM) throws — typically because data.scope is not a ScriptableObject, the Rhino version's reflection of jsFunctionList fails, or method signature checks in defineFunctionProperties reject entries.

Common situations: Rhino version mismatch (custom/updated rhino jar on the classpath replacing the one Pentaho expects, so function-list reflection or method signatures differ); scope initialized in a way that yields a plain (non-ScriptableObject) object; corrupted/partial plugin install where ScriptValuesAddedFunctions class is from an incompatible plugin version.

Related errors


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

Appendix: source

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

            for ( int i = 0; i < meta.getAddClasses().length; i++ ) {
              Object jsOut = Context.javaToJS( meta.getAddClasses()[ i ].getAddObject(), data.scope );
              ScriptableObject.putProperty( data.scope, meta.getAddClasses()[ i ].getJSName(), jsOut );
            }
          }
        } catch ( Exception e ) {
          throw new KettleValueException( BaseMessages.getString(
            PKG, "ScriptValuesMod.Log.CouldNotAttachAdditionalScripts" ), e );
        }

        // Adding some default JavaScriptFunctions to the System
        try {
          Context.javaToJS( ScriptValuesAddedFunctions.class, data.scope );
          ( (ScriptableObject) data.scope ).defineFunctionProperties(
            ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class,
            ScriptableObject.DONTENUM );
        } catch ( Exception ex ) {
          // System.out.println(ex.toString());
          throw new KettleValueException( BaseMessages.getString(
            PKG, "ScriptValuesMod.Log.CouldNotAddDefaultFunctions" ), ex );
        }

        // Adding some Constants to the JavaScript
        try {

          data.scope.put( "SKIP_TRANSFORMATION", data.scope, Integer.valueOf( SKIP_TRANSFORMATION ) );
          data.scope.put( "ABORT_TRANSFORMATION", data.scope, Integer.valueOf( ABORT_TRANSFORMATION ) );
          data.scope.put( "ERROR_TRANSFORMATION", data.scope, Integer.valueOf( ERROR_TRANSFORMATION ) );
          data.scope.put( "CONTINUE_TRANSFORMATION", data.scope, Integer.valueOf( CONTINUE_TRANSFORMATION ) );

        } catch ( Exception ex ) {
          // System.out.println("Exception Adding the Constants " + ex.toString());
          throw new KettleValueException( BaseMessages.getString(
            PKG, "ScriptValuesMod.Log.CouldNotAddDefaultConstants" ), ex );
        }

        try {

View on GitHub (pinned to f3058517a1)