pentaho/pentaho-kettle · error · RhinoRuntimeError

The function call decode requires more than 1 argument.

Error message

The function call decode requires more than 1 argument.

What it means

The Pentaho Kettle ScriptValuesMod JavaScript function `decode(expr, search1, result1, ... [, default])` requires more than 1 argument (at minimum the expression plus one search/result pair or a default). The function throws this Rhino runtime error when `ArgList.length <= 1`, mirroring the Oracle SQL DECODE contract.

Solutions

  1. Call decode with at least 3 arguments: decode(expr, search1, result1, [, search2, result2, ...] [, default])
  2. If you intended a simple null/empty check, use plain JavaScript instead of decode
  3. Verify the field referenced in the first argument exists in the row and is passed correctly

Example fix

// before
var out = decode(value);
// after
var out = decode(value, 'Y', 1, 'N', 0, -1);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof value === 'undefined' || value === null || arguments.length < 3) {
  throw new Error('decode requires (expr, search, result[, ...default])');
}
var out = decode(value, 'Y', 1, 'N', 0, -1);

Type guard

function isDecodeSafe(args) { return Array.isArray(args) && args.length >= 3; }

Prevention

When it happens

Trigger: Calling `decode()` with zero arguments, or exactly one argument (e.g. `decode(myField)`), instead of the required `decode(value, search, result, ...)` form.

Common situations: Developers translating SQL DECODE into a Modified Java/JavaScript step forget the extra arguments; a field whose name resolves to nothing is sometimes mistaken for a valid single-arg call; typo'd variable leaves only the first argument.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:1534

      if ( ArgList.length >= 2 ) {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return Context.getUndefinedValue();
        }
        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 Context.reportRuntimeError( "The function call decode requires more than 1 argument." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( "The function call decode is not valid : " + e.getMessage() );
    }
  }

  public static String replace( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function 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) Context.getUndefinedValue();
        }
        String objForReplace = Context.toString( ArgList[0] );
        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
          objForReplace =

View on GitHub (pinned to f3058517a1)