pentaho/pentaho-kettle · error

The function call getFileExtension is not valid.

Error message

The function call getFileExtension is not valid.

What it means

getFileExtension() is a JavaScript function added by PDI's ScriptValuesMod step. It validates its argument list before performing any VFS work; if it is not called with exactly one non-null, non-undefined argument it throws 'The function call getFileExtension is not valid.' as a JavaScript runtime error, aborting the script execution for that row.

Solutions

  1. Call getFileExtension with exactly one argument
  2. Null/undefined-check the argument variable first
  3. Ensure the upstream step populates the filename field
  4. Handle the error in a try/catch and return a default extension

Example fix

// before
var e = getFileExtension(fname, true);
// after
var e = (fname != null) ? getFileExtension(fname) : '';
Defensive patterns

Strategy: validation

Validate before calling

if (typeof fname === 'undefined' || fname === null || fname === '') {
  throw new Error('getFileExtension requires a non-empty path');
}
var e = getFileExtension(fname);

Type guard

function isStr(v) { return typeof v === 'string'; }

Try / catch

try { var e = getFileExtension(fname); } catch (e) { e = ''; }

Prevention

When it happens

Trigger: Call with zero or multiple arguments, or with a first argument that is null or undefined (guard: ArgList.length == 1 && !isNull && !isUndefined).

Common situations: Filename field missing from the row stream, JavaScript variable name typo, null value produced by an earlier step, or copied code calling with wrong arity.

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

Appendix: source

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

          } else {
            Context.reportRuntimeError( "file [" + Context.toString( ArgList[0] ) + "] can not be found!" );
          }

          return Extension;
        } catch ( IOException e ) {
          throw Context.reportRuntimeError( "The function call getFileExtension throw an error : " + e.toString() );
        } finally {
          if ( file != null ) {
            try {
              file.close();
            } catch ( Exception e ) {
              // Ignore errors
            }
          }
        }

      } else {
        throw Context.reportRuntimeError( "The function call getFileExtension is not valid." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( e.toString() );
    }
  }

  public static String getParentFoldername( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
        if ( ArgList[0].equals( null ) ) {
          return null;
        }
        FileObject file = null;

        try {
          // Source file
          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );

View on GitHub (pinned to f3058517a1)