pentaho/pentaho-kettle · error · RhinoRuntimeError

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

num2str supports exactly 1, 2, or 3 arguments. The switch's default branch throws this error when more than 3 arguments are supplied. The library enforces the documented arity of the function and refuses any other call shape.

Solutions

  1. Remove extra arguments — keep only value, optional pattern, optional 2-letter language code.
  2. Apply unsupported options (rounding, currency) before/after the call instead of via extra parameters.
  3. Check the function's documentation/signature in ScriptValuesAddedFunctions for the supported overloads.

Example fix

// before
var s = num2str(value, "#,##0.00", "de", true); // 4 args

// after
var s = num2str(value, "#,##0.00", "de");
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

function hasValidNum2strArity(args) { return args.length >= 1 && args.length <= 3; }

Prevention

When it happens

Trigger: Calling num2str with 4+ arguments, e.g. num2str(value, pattern, lang, extra) — often from misunderstanding the API or trying to pass extra options like grouping or rounding flags that the function does not support.

Common situations: Porting code from other languages' number-format functions that accept more parameters (e.g. Python's format spec or C#'s ToString overloads); combining options the author guessed existed; accidental leftover arguments after refactoring.

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

Appendix: source

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

            return (String) Context.getUndefinedValue();
          }
          double sArg1 = Context.toNumber( ArgList[0] );
          if ( Double.isNaN( sArg1 ) ) {
            throw Context.reportRuntimeError( "The first Argument must be a Number." );
          }
          String sArg2 = Context.toString( ArgList[1] );
          String sArg3 = Context.toString( 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 Context.reportRuntimeError( e.toString() );
        }
        break;
      default:
        throw Context.reportRuntimeError( "The function call num2str requires 1, 2, or 3 arguments." );
    }

    return sRC;
  }

  // Converts the given String to a JScript Numeric
  public static Object str2num( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    double dRC = 0.00;
    switch ( ArgList.length ) {
      case 0:
        throw Context.reportRuntimeError( "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 Context.getUndefinedValue();

View on GitHub (pinned to f3058517a1)