{"record":{"id":"64133d81ecea6555","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getparentfoldername-is-not-valid-64133d","errorCode":null,"errorMessage":"The function call getParentFoldername is not valid.","messagePattern":"The function call getParentFoldername is not valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2417,"sourceCode":"            Context.reportRuntimeError( \"file [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n\n          return foldername;\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"The function call getParentFoldername throw an error : \"\n            + e.toString() );\n        } finally {\n          if ( file != null ) {\n            try {\n              file.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {\n        throw Context.reportRuntimeError( \"The function call getParentFoldername is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static String getLastModifiedTime( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    try {\n      if ( ArgList.length == 2 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {\n        if ( ArgList[0].equals( null ) ) {\n          return null;\n        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( getBowl( actualObject ) ).getFileObject( Context.toString( ArgList[0] ) );","sourceCodeStart":2399,"sourceCodeEnd":2435,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2399-L2435","documentation":"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.","triggerScenarios":"Invoking getParentFoldername() with zero or multiple arguments, or with a null/undefined first argument (guard: ArgList.length == 1 && !isNull && !isUndefined).","commonSituations":"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.","solutions":["Pass exactly one path argument","Guard the variable against null/undefined before the call","Repair the upstream step so the path field is populated","Catch the runtime error in script and default the result"],"exampleFix":"// before\nvar p = getParentFoldername();\n// after\nvar p = (fpath != null) ? getParentFoldername(fpath) : null;","handlingStrategy":"validation","validationCode":"if (typeof fpath === 'undefined' || fpath === null) {\n  throw new Error('fpath required for getParentFoldername');\n}\nvar p = getParentFoldername(fpath);","typeGuard":"function hasValue(v) { return v !== undefined && v !== null; }","tryCatchPattern":"try { var p = getParentFoldername(fpath); } catch (e) { p = null; }","preventionTips":["Exactly one argument per call","Null-check variables sourced from fields","Fix upstream nulls early in the transform","Use defensive try/catch in script steps"],"tags":["javascript","argument-count","kettle"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}