pentaho/pentaho-kettle · error · Rhino runtime error

The function call initCap requires 1 argument.

Error message

The function call initCap requires 1 argument.

What it means

initCap capitalizes the first letter of each word via Const.initCap in the Modified Java Script Value step. This error is thrown when the function is invoked with an argument count other than exactly 1 — only a single string input is supported.

Solutions

  1. Call initCap with exactly one argument: initCap(nameField)
  2. Remove extra parameters such as locale (unsupported)
  3. Handle null/undefined fields before calling to avoid other JS errors

Example fix

// before
var capped = initCap(name, "en");
// after
var capped = initCap(name);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof name === 'string' && name.length > 0) { var capped = initCap(name); }

Type guard

function isNonEmptyString(v){ return typeof v === 'string' && v.length > 0; }

Try / catch

try { var capped = initCap(name); } catch (e) { throw new Error('initCap requires exactly 1 argument: ' + e.message); }

Prevention

When it happens

Trigger: initCap() with zero arguments or initCap(s, extra) with multiple arguments; ArgList.length != 1 reaches the else branch and throws.

Common situations: Users attempting to pass a locale as a second argument; scripts where the field argument was removed leaving an empty call.

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

Appendix: source

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

    }
  }

  public static String removeDigits( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    if ( ArgList.length == 1 ) {
      return Const.removeDigits( Context.toString( ArgList[0] ) );
    } else {
      throw Context.reportRuntimeError( "The function call removeDigits requires 1 argument." );

    }
  }

  public static String initCap( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    if ( ArgList.length == 1 ) {
      return Const.initCap( Context.toString( ArgList[0] ) );
    } else {
      throw Context.reportRuntimeError( "The function call initCap requires 1 argument." );

    }
  }

  public static Object loadFileContent( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    Object oRC = new Object();
    try {

      switch ( ArgList.length ) {
        case 0:
          throw Context.reportRuntimeError( "Please provide a filename to the function call loadFileContent." );
        case 1:
          try {
            if ( isNull( ArgList ) ) {
              return null;
            } else if ( isUndefined( ArgList ) ) {
              return Context.getUndefinedValue();

View on GitHub (pinned to f3058517a1)