pentaho/pentaho-kettle · error · RuntimeException

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

Error message

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

What it means

str2num only supports 1, 2, or 3 arguments (value, optional pattern, optional locale). If the JS script calls it with zero arguments or more than three, the switch falls to the default branch and this RuntimeException is thrown to fail the transformation step.

Solutions

  1. Call str2num with exactly 1-3 arguments: str2num(value) or str2num(value, pattern) or str2num(value, pattern, locale).
  2. Check the call site in your JavaScript step for extra/missing arguments.
  3. If you need more options, do the parsing manually with java.text.DecimalFormat in the script.

Example fix

// before
var n = str2num(value, '#,##0.00', 'en', true); // 4 args -> throws
// after
var n = str2num(value, '#,##0.00', 'en');
Defensive patterns

Strategy: validation

Validate before calling

function safeStr2num() {
  if (arguments.length < 1 || arguments.length > 3) {
    throw new Error('str2num requires 1, 2, or 3 arguments');
  }
  return str2num.apply(null, arguments);
}

Try / catch

try {
  var n = str2num(v, pattern, locale);
} catch (e) {
  if (String(e.message).indexOf('requires 1, 2, or 3') >= 0) {
    // fix arity at call site / alert developer
  }
}

Prevention

When it happens

Trigger: Calling str2num() with no arguments, or str2num(a, b, c, d) with four or more arguments from a JavaScript step.

Common situations: Refactoring scripts and leaving stale arguments, passing an array without spreading it, copy-paste errors between differently-arity helper functions.

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

Appendix: source

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

            return new Double( Double.NaN );
          } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
            return undefinedValue;
          }
          String sArg1 = (String) ArgList[0];
          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 );
            dRC = ( formatter.parse( sArg1 ) ).doubleValue();
            return new Double( dRC );
          }
        } catch ( Exception e ) {
          throw new RuntimeException( e.getMessage() );
        }
        break;
      default:
        throw new RuntimeException( "The function call str2num requires 1, 2, or 3 arguments." );
    }
    return new Double( dRC );
  }

  public static Object isNum( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {

    if ( ArgList.length == 1 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return undefinedValue;
        }
        double sArg1 = (Double) ArgList[0];
        if ( Double.isNaN( sArg1 ) ) {
          return Boolean.FALSE;
        } else {

View on GitHub (pinned to f3058517a1)