pentaho/pentaho-kettle · error

Please provide a valid Char to the fillString

Error message

Please provide a valid Char to the fillString

What it means

fillString repeats a single character N times to produce a padded string in Kettle's JavaScript step. The first argument must be exactly one character; if fillChar.length() != 1 the function throws this RuntimeError instead of silently accepting multi-character or empty input.

Solutions

  1. Pass exactly one character as the first argument: fillString('-', 10)
  2. If you need a multi-character pattern repeated, use a JavaScript loop or Array(count+1).join(str) instead
  3. Trim or slice the input character source before the call

Example fix

// before
var pad = fillString('..', 20);
// after
var pad = fillString('.', 20);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof ch !== 'string' || ch.length !== 1) throw new Error('fillString needs a single character');
var s = fillString(ch, count);

Type guard

function isSingleChar(v) { return typeof v === 'string' && v.length === 1; }

Try / catch

try { var s = fillString(ch, n); } catch (e) { if (String(e).indexOf('valid Char') >= 0) { /* use first char */ } }

Prevention

When it happens

Trigger: Calling fillString('--', 10) or fillString('', 5) - a multi-character or empty string passed as the fill character.

Common situations: Users expect fillString to repeat a whole prefix string (like JS String.repeat); passing a two-dash separator or a space plus character from a config field.

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/51a0a216104948ea. Report an issue: GitHub.

Appendix: source

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

      }
    } else {
      throw Context.reportRuntimeError( "The function call dateAdd requires 3 arguments." );
    }
  }

  public static String fillString( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    if ( ArgList.length == 2 ) {
      try {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return (String) Context.getUndefinedValue();
        }
        String fillChar = Context.toString( ArgList[0] );
        int count = (int) Context.toNumber( ArgList[1] );
        if ( fillChar.length() != 1 ) {
          throw Context.reportRuntimeError( "Please provide a valid Char to the fillString" );
        } else {
          char[] chars = new char[count];
          while ( count > 0 ) {
            chars[--count] = fillChar.charAt( 0 );
          }
          return new String( chars );
        }
      } catch ( Exception e ) {
        throw Context.reportRuntimeError( e.toString() );
      }
    } else {
      throw Context.reportRuntimeError( "The function call fillString requires 2 arguments." );
    }
  }

  public static Object isCodepage( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    boolean bRC = false;

View on GitHub (pinned to f3058517a1)