pentaho/pentaho-kettle · error

The function call rtrim is not valid :

Error message

The function call rtrim is not valid : 

What it means

In Kettle/Pentaho's JavaScript scripting step (ScriptValuesAddedFunctions), the rtrim() JS function trims trailing whitespace via a regex replaceAll. Any exception thrown inside rtrim() — including wrong argument counts or non-string arguments — is caught and re-thrown as this generic 'The function call rtrim is not valid' runtime error, with the underlying message appended.

Solutions

  1. Ensure rtrim() is called with exactly one argument that is a defined value.
  2. Null-check the field value in the script before calling rtrim().
  3. Inspect the appended e.getMessage() in the error to find the real underlying cause.
  4. Log the argument value before the call to confirm its type/content.

Example fix

// before
var trimmed = rtrim(myField); // myField may be null
// after
var trimmed = (myField != null) ? rtrim(myField.toString()) : null;
Defensive patterns

Strategy: validation

Validate before calling

if (typeof myField === 'undefined' || myField === null) { throw 'rtrim: input field is null'; }
var trimmed = rtrim(String(myField));

Type guard

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

Try / catch

try { var trimmed = rtrim(String(myField)); } catch (e) { // fall back to untrimmed value
  var trimmed = String(myField); }

Prevention

When it happens

Trigger: Calling rtrim() in a modified JavaScript step with zero arguments (hits the requires-1-argument branch first), or with an argument that cannot be converted or causes an exception inside the regex replace (e.g. null/undefined value passed from a field).

Common situations: Script authors pass a null field value to rtrim(), forget the argument entirely, or pass a non-string object; the wrapper catches the resulting exception and surfaces it with this message.

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

Appendix: source

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

    }
  }

  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 {
        throw Context.reportRuntimeError( "The function call rtrim requires 1 argument." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( "The function call rtrim is not valid : " + e.getMessage() );
    }
  }

  public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {

    // (String valueToPad, String filler, int size) {
    try {
      if ( ArgList.length == 3 ) {
        if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
          return (String) Context.getUndefinedValue();
        }
        String valueToPad = Context.toString( ArgList[0] );
        String filler = Context.toString( ArgList[1] );
        int size = (int) Context.toNumber( ArgList[2] );

View on GitHub (pinned to f3058517a1)