pentaho/pentaho-kettle · error

The function call getParentFoldername is not valid.

Error message

The function call getParentFoldername is not valid.

What it means

getParentFoldername() is a JavaScript function exposed by the ScriptValuesMod step. It enforces an exact single-argument contract before any VFS access; calls without exactly one non-null, non-undefined argument throw 'The function call getParentFoldername is not valid.' as a JavaScript runtime error.

Solutions

  1. Pass exactly one path argument
  2. Guard the variable against null/undefined before the call
  3. Repair the upstream step so the path field is populated
  4. Catch the runtime error in script and default the result

Example fix

// before
var p = getParentFoldername();
// after
var p = (fpath != null) ? getParentFoldername(fpath) : null;
Defensive patterns

Strategy: validation

Validate before calling

if (typeof fpath === 'undefined' || fpath === null) {
  throw new Error('fpath required for getParentFoldername');
}
var p = getParentFoldername(fpath);

Type guard

function hasValue(v) { return v !== undefined && v !== null; }

Try / catch

try { var p = getParentFoldername(fpath); } catch (e) { p = null; }

Prevention

When it happens

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

Common situations: Undefined folder/filename variable from a typo or missing upstream field, null values flowing through the row stream, or wrong arity after refactoring the script.

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

Appendix: source

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

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

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

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

  public static String getLastModifiedTime( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    try {
      if ( ArgList.length == 2 && !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)