pentaho/pentaho-kettle · error

The function call ltrim requires 1 argument.

Error message

The function call ltrim requires 1 argument.

What it means

Argument-count guard in ScriptValuesAddedFunctions.ltrim, which strips leading whitespace from a string. It fires when a JavaScript script calls ltrim with an argument count other than exactly 1; the guard raises a Rhino runtime error instead of proceeding. Fix by passing exactly one string argument, e.g. ltrim(myField).

Solutions

  1. Call with a single string argument: ltrim(myString)
  2. For custom character trimming, use myString.replace(/^[chars]+/, '') directly
  3. Ensure the argument is a string (or undefined-aware) before calling

Example fix

// before
var s = ltrim(value, ' ');
// after
var s = ltrim(value);
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof s !== 'string') s = String(s == null ? '' : s);
var t = ltrim(s);

Type guard

function isStr(v) { return typeof v === 'string'; }

Try / catch

try { var t = ltrim(s); } catch (e) { if (String(e).indexOf('requires 1 argument') >= 0) { /* fix arity */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling ltrim() with no arguments, or ltrim(str, chars) with a second 'characters to trim' argument that this implementation does not accept.

Common situations: Users coming from SQL LTRIM(expr, set) or Oracle syntax expecting a character-set parameter; calling with a comma-separated list intended as one argument.

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

Appendix: source

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

    } else {
      throw Context.reportRuntimeError( "The function call isCodepage requires 2 arguments." );
    }
    return Boolean.valueOf( bRC );
  }

  public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 1 ) {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) Context.getUndefinedValue();
        }
        String strValueToTrim = Context.toString( ArgList[0] );
        return strValueToTrim.replaceAll( "^\\s+", "" );
      } else {
        throw Context.reportRuntimeError( "The function call ltrim requires 1 argument." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( "The function call ltrim is not valid : " + e.getMessage() );
    }
  }

  public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 1 ) {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) Context.getUndefinedValue();
        }
        String strValueToTrim = Context.toString( ArgList[0] );
        return strValueToTrim.replaceAll( "\\s+$", "" );
      } else {

View on GitHub (pinned to f3058517a1)