pentaho/pentaho-kettle · error · RuntimeException

The function call fileExists requires 1 valid argument.

Error message

The function call fileExists requires 1 valid argument.

What it means

fileExists() checks whether a path exists as a file and requires exactly one String argument. This RuntimeException is thrown when the argument count is not 1 or the argument is not a String. It is a precondition guard thrown before any filesystem access.

Solutions

  1. Call fileExists with exactly one String path: fileExists('/path/to/file').
  2. Coerce the field to a string first, e.g. fileExists(String(myPath)).
  3. Guard against null in script before the call if the field may be empty.

Example fix

// before
var exists = fileExists(someRow.field);
// after
var exists = fileExists(String(someRow.field));
Defensive patterns

Strategy: validation

Validate before calling

if (p != null && (typeof p === 'string' || p instanceof java.lang.String) && p.length > 0) { var exists = fileExists(p); }

Type guard

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

Try / catch

try { var ex = fileExists(p); } catch (e) { logError('fileExists failed: ' + e.message); ex = false; }

Prevention

When it happens

Trigger: Calling fileExists() with no arguments, with two or more arguments, or with a non-String value such as a numeric field or null object.

Common situations: Passing a Kettle field of non-string type; forgetting the path argument after refactoring the script; passing a JavaScript object built from JSON instead of the path string.

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/1894ec0c676dfcf3. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:978

      } else {
        throw new RuntimeException( "The function call touch requires 1 valid argument." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( e.toString() );
    }
  }

  public static Object fileExists( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    try {
      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
        if ( ArgList[0].equals( null ) ) {
          return null;
        }
        File file = new File( (String) ArgList[0] );
        return Boolean.valueOf( file.isFile() );
      } else {
        throw new RuntimeException( "The function call fileExists requires 1 valid argument." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( e.toString() );
    }
  }

  public static Object str2date( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    Object oRC = new Object();
    String sArg1 = "";
    String sArg2 = "";
    String sArg3 = "";
    String sArg4 = "";
    switch ( ArgList.length ) {
      case 0:
        throw new RuntimeException( "Please provide a valid string to the function call str2date." );
      case 1:
        try {

View on GitHub (pinned to f3058517a1)