pentaho/pentaho-kettle · error · KettleFileException

Row.RowError

Error message

Row.RowError

What it means

The substr scripting function wraps any exception from the 2-argument form (string conversion, number conversion of the start index, or String.substring) into this Rhino runtime error with e.getMessage() appended. It fires when exactly 2 arguments were passed but processing them failed. Common underlying causes are non-numeric start values and StringIndexOutOfBoundsException.

Solutions

  1. Ensure the second argument is a finite number: substr(str, Number(start)).
  2. Guard the input string: if (str == null) str = ''; before calling.
  3. Clamp the start index: var s = Math.max(0, Math.min(start, String(str).length)).
  4. Consider native JavaScript substring/slice for predictable behavior.

Example fix

// before
substr(value, "position"); // non-numeric start
// after
substr(String(value), parseInt(pos, 10) || 0);
Defensive patterns

Strategy: validation

Validate before calling

var s = String(str == null ? "" : str);
var start = Math.max(0, Math.round(Number(fromArg) || 0));
if (start > s.length) start = s.length;

Type guard

function isFiniteNumber(x) { return typeof x === "number" && isFinite(x); }

Try / catch

var r;
try {
  r = substr(String(str), Number(start) || 0);
} catch (e) {
  r = ""; // safe default on conversion failure
}

Prevention

When it happens

Trigger: Calling substr(str, start) with exactly 2 arguments where start is not convertible to a number (NaN), or str.substring(from) throws because from is out of range for the converted string.

Common situations: Passing a field that is null/empty causing Number conversion to NaN then an out-of-range substring; passing a non-numeric second argument like a string label; off-by-one assumptions vs JavaScript's native substr semantics.

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/616d0488ffb77d7e. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Row.java:529

   * @param dis
   *          The DataInputStream to read from
   * @param size
   *          the number or values to read
   * @param meta
   *          The description (name, type, length, precision) of the values to be read
   * @throws KettleFileException
   *           if the row couldn't be created by reading from the data input stream.
   */
  public Row( DataInputStream dis, int size, Row meta ) throws KettleFileException {
    try {
      // get all values in the row
      for ( int i = 0; i < size; i++ ) {
        addValue( new Value( meta.getValue( i ), dis ) );
      }
    } catch ( KettleEOFException e ) {
      throw new KettleEOFException( BaseMessages.getString( PKG, "Row.EndOfFileReadingRow" ), e );
    } catch ( Exception e ) {
      throw new KettleFileException( BaseMessages.getString( PKG, "Row.RowError" ), e );
    }
  }

  /**
   * Write a row of Values to a DataOutputStream, without saving the meta-data.
   *
   * @param dos
   *          The DataOutputStream to write to
   * @return true if the row was written successfuly, false if something went wrong.
   */
  public boolean writeData( DataOutputStream dos ) throws KettleFileException {
    // get all values in the row
    for ( int i = 0; i < size(); i++ ) {
      Value v = getValue( i );
      v.writeData( dos );
    }

    return true;

View on GitHub (pinned to f3058517a1)