pentaho/pentaho-kettle · error

The function call rpad requires 3 arguments.

Error message

The function call rpad requires 3 arguments.

What it means

The rpad() function pads a string on the right to a given size with a filler string. Like lpad(), it expects exactly 3 arguments and wraps any exception (argument count, null value, conversion failure) into this 'requires 3 arguments' runtime error.

Solutions

  1. Call rpad() with exactly 3 arguments: value, target size, filler string.
  2. Null-check the value before calling.
  3. Ensure size is numeric and filler is a non-empty string.
  4. Wrap the call in a conditional that uses a default filler when omitted.

Example fix

// before
var padded = rpad(myField, 8);
// after
var padded = rpad(myField, 8, ' ');
Defensive patterns

Strategy: validation

Validate before calling

if (myField == null) throw 'rpad: value is null';
var padded = rpad(String(myField), 8, ' ');

Type guard

function canRpad(v, size, filler) { return v != null && typeof size === 'number' && typeof filler === 'string' && filler.length > 0; }

Try / catch

try { var padded = rpad(String(myField), 8, ' '); } catch (e) { var padded = String(myField); }

Prevention

When it happens

Trigger: Calling rpad() in a modified JavaScript step with fewer than 3 arguments (e.g. rpad(field, 8)), or with a null value / non-numeric size causing an exception inside the padding loop.

Common situations: Scripts modeled on SQL RPAD (filler optional there), fields that arrive null, or size given as a string instead of a number.

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

Appendix: source

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

    Function FunctionContext ) {
    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] );

        while ( valueToPad.length() < size ) {
          valueToPad = valueToPad + filler;
        }
        return valueToPad;
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( "The function call rpad requires 3 arguments." );
    }
    return null;
  }

  public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 1 ) {
        if ( isNull( ArgList[0] ) ) {
          return new Double( Double.NaN );
        } else if ( isUndefined( ArgList[0] ) ) {
          return Context.getUndefinedValue();
        }
        java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[0], java.util.Date.class );
        Calendar cal = Calendar.getInstance();
        cal.setTime( dArg1 );
        return new Double( cal.get( Calendar.YEAR ) );
      } else {

View on GitHub (pinned to f3058517a1)