pentaho/pentaho-kettle · error · RuntimeException

The function call trim requires 1 argument.

Error message

The function call trim requires 1 argument.

What it means

Arity guard for the trim script function: it was called with more (or fewer) than one argument. trim strips whitespace from a single string via Const.trim, so exactly one argument is required; the else-branch rejects all other counts.

Solutions

  1. Call trim with exactly one argument per field: trim(field1); trim(field2).
  2. Remove extra arguments; trim does not accept a character-set argument like some other languages' APIs.
  3. If you need multi-field trimming, write a small wrapper loop in the script.

Example fix

// before
var t = trim(a, b);
// after
var t = trim(a); var t2 = trim(b);
Defensive patterns

Strategy: validation

Validate before calling

if (arguments.length === 1) { t = trim(arguments[0]); } else { t = ''; }

Type guard

function hasOneArg(args){ return args.length === 1; }

Try / catch

try { t = trim(value); } catch (e) { if (/requires 1 argument/.test(e.message)) t = ''; else throw e; }

Prevention

When it happens

Trigger: Calling trim() with zero arguments or trim(a, b) with extra arguments in JavaScript step code.

Common situations: Mistakenly calling trim on multiple fields at once (expecting variadic behavior); copy-paste errors leaving an extra comma.

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

Appendix: source

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

  }

  public static String trim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String sRC = "";
    if ( ArgList.length == 1 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) undefinedValue;
        }
        sRC = (String) ArgList[0];
        sRC = Const.trim( sRC );
      } catch ( Exception e ) {
        throw new RuntimeException( "The function call trim is not valid : " + e.getMessage() );
      }
    } else {
      throw new RuntimeException( "The function call trim requires 1 argument." );
    }
    return sRC;
  }

  public static String substr( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    String sRC = "";

    if ( ArgList.length == 2 ) {
      try {
        if ( isNull( ArgList[0] ) ) {
          return null;
        } else if ( isUndefined( ArgList[0] ) ) {
          return (String) undefinedValue;
        }
        sRC = (String) ArgList[0];
        int from = (int) Math.round( (Double) ArgList[1] );
        sRC = sRC.substring( from );

View on GitHub (pinned to f3058517a1)