pentaho/pentaho-kettle · error · RuntimeException

The function call trim is not valid :

Error message

The function call trim is not valid : 

What it means

Thrown when the trim() helper in the JavaScript step throws any exception while processing its single argument (the arity error at the same call site is separate). The message appends the underlying exception text after the colon. It typically means the argument could not be cast/handled as a string.

Solutions

  1. Convert the value explicitly before trimming: trim('' + value) or trim(value.toString()).
  2. Guard against null: trim(value == null ? '' : value + '').
  3. Read the appended e.getMessage() in the message to identify the actual failure.

Example fix

// before
var t = trim(123);
// after
var t = trim('' + 123);
Defensive patterns

Strategy: type-guard

Validate before calling

function safeTrim(v){ return (v === null || v === undefined) ? '' : Const.trim('' + v); }

Type guard

function isTrimable(v){ return v !== null && v !== undefined; }

Try / catch

try { t = trim(value); } catch (e) { t = ''; logError('trim failed: ' + e.message); }

Prevention

When it happens

Trigger: Calling trim(x) where x is not a string (e.g. a number, null at runtime, or an object) so (String) ArgList[0] or Const.trim throws; also when ArgList[0] is a value that fails conversion in the try block.

Common situations: Trimming a numeric field read from a row without converting it; trimming a field that is null; feeding the output of another function that returned a non-string.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/aa038c38af6bcf6f. Report an issue: GitHub.

Appendix: source

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

      throw new RuntimeException( "The function call getEnvironmentVar requires 1 argument." );
    }
    return sRC;
  }

  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;
        }

View on GitHub (pinned to f3058517a1)