pentaho/pentaho-kettle · error · RuntimeException

The function call num2str requires 1, 2, or 3 arguments.

Error message

The function call num2str requires 1, 2, or 3 arguments.

What it means

Arity guard in the num2str script function: the JS/JSR-223 call site passed an unsupported number of arguments. num2str formats a number to a string using an optional DecimalFormat pattern (arg2) and optional 2-letter locale (arg3), so only the 1-, 2-, and 3-argument forms are valid; any other count reaches this else-branch and aborts the transformation.

Solutions

  1. Call num2str with exactly 1, 2, or 3 arguments.
  2. Add a default for missing arguments: num2str(value || 0, pattern || "#,##0.00").
  3. Check argument count in script before calling: if (arguments.length >= 1 && arguments.length <= 3).

Example fix

// before
var s = num2str(1234.5, "#,##0.00", "en", "extra");
// after
var s = num2str(1234.5, "#,##0.00", "en");
Defensive patterns

Strategy: validation

Validate before calling

if (arguments.length >= 1 && arguments.length <= 3) { var s = num2str.apply(null, arguments); }

Try / catch

try { return num2str(v, p, loc); } catch (e) { if (String(e).indexOf("requires 1, 2, or 3 arguments") >= 0) return ""; throw e; }

Prevention

When it happens

Trigger: Calling num2str() with no arguments, or with 4+ arguments, inside a JavaScript/V Rhino script in the Kettle scripting step.

Common situations: Copy-paste errors leaving a stray argument; forgetting the number argument entirely; refactoring scripts where a variable became undefined and arguments.length collapsed to 0.

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

Appendix: source

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

            return (String) undefinedValue;
          }
          double sArg1 = (Double) ArgList[0];
          if ( Double.isNaN( sArg1 ) ) {
            throw new RuntimeException( "The first Argument must be a Number." );
          }
          String sArg2 = (String) ArgList[1];
          String sArg3 = (String) ArgList[2];
          if ( sArg3.length() == 2 ) {
            DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );
            DecimalFormat formatter = new DecimalFormat( sArg2, dfs );
            sRC = formatter.format( sArg1 );
          }
        } catch ( Exception e ) {
          throw new RuntimeException( e.toString() );
        }
        break;
      default:
        throw new RuntimeException( "The function call num2str requires 1, 2, or 3 arguments." );
    }

    return sRC;
  }

  // Converts the given String to a JScript Numeric
  public static Object str2num( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    double dRC = 0.00;
    switch ( ArgList.length ) {
      case 0:
        throw new RuntimeException( "The function call str2num requires at least 1 argument." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return new Double( Double.NaN );
          } else if ( isUndefined( ArgList[0] ) ) {
            return undefinedValue;

View on GitHub (pinned to f3058517a1)