pentaho/pentaho-kettle · error · JavaScriptException

The function call num2str requires at least 1 argument.

Error message

The function call num2str requires at least 1 argument.

What it means

The num2str JavaScript function (registered by ScriptValuesAddedFunctions for the Modified Java Script Value step) converts a numeric value to a formatted string. It requires at least one argument; when called with zero arguments, it throws this Rhino runtime error via Context.reportRuntimeError. The library enforces the 1-3 argument arity contract of num2str.

Solutions

  1. Pass the number to format as the first argument: num2str(myNumericField).
  2. Check the script for the call site and ensure the field/variable actually exists in the step's input rows.
  3. If the value may be null/undefined, guard before calling: only call num2str when the value is not null.

Example fix

// before
var s = num2str();

// after
var s = num2str(price); // price is a numeric field from the incoming row
Defensive patterns

Strategy: validation

Validate before calling

function safeNum2str(v) {
  if (v === null || v === undefined) return null;
  return num2str(v);
}

Type guard

function isNumericArg(v) { return v !== null && v !== undefined && !isNaN(Number(v)); }

Prevention

When it happens

Trigger: Calling num2str() with no arguments in a JavaScript step script: e.g. `var s = num2str();`. ArgList.length == 0 hits `case 0` of the switch and throws immediately.

Common situations: Typos where the argument was dropped during edit; copy-paste of num2str from examples without replacing the placeholder; calling the function before the variable holding the number was assigned and assuming a default; porting scripts where a variable name was lost.

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

Appendix: source

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

        }
        sRC = Context.toString( ArgList[0] );
        sRC = sRC.toLowerCase();
      } catch ( Exception e ) {
        throw Context.reportRuntimeError( "The function call lower is not valid : " + e.getMessage() );
      }
    } else {
      throw Context.reportRuntimeError( "The function call lower requires 1 argument." );
    }
    return sRC;
  }

  // Converts the given Numeric to a JScript String
  public static String num2str( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    String sRC = "";
    switch ( ArgList.length ) {
      case 0:
        throw Context.reportRuntimeError( "The function call num2str requires at least 1 argument." );
      case 1:
        try {
          if ( isNull( ArgList[0] ) ) {
            return null;
          } else if ( isUndefined( ArgList[0] ) ) {
            return (String) Context.getUndefinedValue();
          }
          double sArg1 = Context.toNumber( ArgList[0] );
          if ( Double.isNaN( sArg1 ) ) {
            throw Context.reportRuntimeError( "The first Argument must be a Number." );
          }
          DecimalFormat formatter = new DecimalFormat();
          sRC = formatter.format( sArg1 );
        } catch ( IllegalArgumentException e ) {
          throw Context.reportRuntimeError( "Could not apply the given format on the number : " + e.getMessage() );
        }
        break;
      case 2:

View on GitHub (pinned to f3058517a1)