{"record":{"id":"367d1a8d58d80f48","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getparentfoldername-throw-an-error","errorCode":null,"errorMessage":"The function call getParentFoldername throw an error : ","messagePattern":"The function call getParentFoldername throw an error : ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2404,"sourceCode":"        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] ) );\n          String foldername = null;\n          if ( file.exists() ) {\n            foldername = KettleVFS.getFilename( file.getParent() );\n\n          } else {\n            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  }","sourceCodeStart":2386,"sourceCodeEnd":2422,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2386-L2422","documentation":"getParentFoldername() returns the parent folder of the file identified by its single argument via KettleVFS. If a java.io.IOException is thrown while resolving or inspecting the VFS object, the function converts it to a JavaScript runtime error: 'The function call getParentFoldername throw an error : ' plus the exception message. This indicates a filesystem/VFS-level failure rather than a scripting mistake.","triggerScenarios":"KettleVFS.getFileObject() or file operations throwing IOException — malformed or unsupported VFS URI, unreachable network filesystem, provider resolution failure, or I/O errors during resolution/close.","commonSituations":"SFTP/SMB mounts down or credentials expired, special characters not URL-encoded in paths, wrong URI scheme, commons-vfs provider version incompatibilities.","solutions":["Validate the path is a resolvable VFS URI before calling","Check the remote filesystem availability and credentials","Normalize relative paths to fully qualified URIs","Update/align commons-vfs and provider libraries"],"exampleFix":"// before\nvar parent = getParentFoldername('sftp://host/dir with space/f.txt');\n// after\nvar parent = getParentFoldername('sftp://host/dir%20with%20space/f.txt');","handlingStrategy":"try-catch","validationCode":"var f = isFile(path); // fail fast on unresolvable URIs","typeGuard":"function isVfsUri(v) { return typeof v === 'string' && v.indexOf('://') > 0; }","tryCatchPattern":"try { var p = getParentFoldername(path); } catch (e) {\n  // 'getParentFoldername throw an error : <IOException>'\n  p = null; }","preventionTips":["Use properly encoded, fully qualified URIs","Monitor remote filesystem health before runs","Escape special characters","Keep VFS provider dependencies current"],"tags":["io","vfs","filesystem"],"backgroundTag":"file-read-failed","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"}