pentaho/pentaho-kettle · error · KettleFileException

Unable to write value to output stream

Error message

Unable to write value to output stream

What it means

substr accepts only the 2-argument (start) and 3-argument (start, length) forms. This argument-count guard at ScriptValuesAddedFunctions.java:1703 throws when ArgList.length is anything other than 2 or 3. The message mirrors JavaScript's flexibility expectations but the Kettle implementation is strict.

Solutions

  1. Always pass a start index: substr(str, 0) to get the whole string.
  2. Remove any extra arguments beyond start and length.
  3. Use native JavaScript slice for flexible/omittable arguments.

Example fix

// before
substr(str); // missing start
// after
substr(str, 0);
Defensive patterns

Strategy: validation

Validate before calling

if (arguments.length < 2 || arguments.length > 3) throw new Error("substr requires start (and optional length)");

Type guard

null

Try / catch

var r;
try {
  r = substr(String(str == null ? "" : str), 0);
} catch (e) {
  r = "";
}

Prevention

When it happens

Trigger: Calling substr() with zero or one argument, or with 4+ arguments such as substr(str, start, len, extra).

Common situations: Forgetting the mandatory start argument (native JS substr requires only length optionally); passing extra options; calling with only a string expecting the whole-string default.

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/6e7f4e4831d9cc77. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:1542

        default:
          break; // nothing
      }
    }
  }

  /**
   * Write the value, including the meta-data to a DataOutputStream
   *
   * @param outputStream
   *          the OutputStream to write to .
   * @throws KettleFileException
   *           if something goes wrong.
   */
  public void write( OutputStream outputStream ) throws KettleFileException {
    try {
      writeObj( new DataOutputStream( outputStream ) );
    } catch ( Exception e ) {
      throw new KettleFileException( "Unable to write value to output stream", e );
    }
  }

  /**
   * Read the metadata and data for this Value object from the specified data input stream
   *
   * @param dis
   * @throws IOException
   */
  public void readObj( DataInputStream dis ) throws IOException {
    // type
    int theType = dis.readInt();
    newValue( theType );

    // name-length
    int nameLength = dis.readInt();

    // name

View on GitHub (pinned to f3058517a1)