pentaho/pentaho-kettle · error · RuntimeException

The function call decode is not valid : " + e.getMessage()

Error message

The function call decode is not valid : " + e.getMessage()

What it means

decode wraps any exception thrown inside its comparison logic in a new RuntimeException prefixed with 'The function call decode is not valid : '. This can be triggered by argument-count problems caught inside the try block or errors while evaluating the comparison values, and it flattens the original exception to just its message.

Solutions

  1. Check the trailing message after the colon to identify the root cause.
  2. Validate argument types and count before calling decode (more than 1 argument).
  3. Replace complex decode calls with explicit if/else in the script for easier debugging.

Example fix

// before
var r = decode(null, x, 1, 0); // may throw with cast/NPE message
// after
var r = (status == null) ? 0 : decode(status, x, 1, 0);
Defensive patterns

Strategy: try-catch

Validate before calling

function safeDecode() {
  if (arguments.length < 2) return arguments.length ? arguments[0] : null;
  try { return decode.apply(null, arguments); }
  catch (e) { return null; }
}

Type guard

function allStrings(arr) {
  return arr.every(function(a) { return typeof a === 'string' || a === null; });
}

Try / catch

try {
  var r = decode(status, 'A', 1, 0);
} catch (e) {
  // message after 'not valid : ' names the root cause - log it fully
  Logger.log(e.message);
  var r = 0;
}

Prevention

When it happens

Trigger: Any Exception during decode execution - including inner arithmetic/cast errors or a caught arity error - surfaces with this message in a JavaScript step.

Common situations: Passing non-comparable object types to decode, null values failing casts, nested decode errors whose messages get concatenated.

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/ca4e6dbe3df7c46e. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1502

        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return undefinedValue;
        }
        Object objToCompare = ArgList[0];
        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
          if ( ArgList[i].equals( objToCompare ) ) {
            return ArgList[i + 1];
          }
        }
        if ( ArgList.length % 2 == 0 ) {
          return ArgList[ArgList.length - 1];
        } else {
          return objToCompare;
        }
      } else {
        throw new RuntimeException( "The function call decode requires more than 1 argument." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( "The function call decode is not valid : " + e.getMessage() );
    }
  }

  public static String replace( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    try {
      if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return (String) undefinedValue;
        }
        String objForReplace = (String) ArgList[0];
        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
          objForReplace = objForReplace.replaceAll( (String) ArgList[i], (String) ArgList[i + 1] );
        }
        return objForReplace;
      } else {

View on GitHub (pinned to f3058517a1)