{"record":{"id":"116dc3a6e49dd425","repo":"pentaho/pentaho-kettle","slug":"the-function-call-getparentfoldername-throw-an-error-e","errorCode":null,"errorMessage":"The function call getParentFoldername throw an error :  + e.toString()","messagePattern":"The function call getParentFoldername throw an error :  \\+ e\\.toString\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2316,"sourceCode":"        if ( ArgList[0].equals( null ) ) {\n          return null;\n        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );\n          String foldername = null;\n          if ( file.exists() ) {\n            foldername = KettleVFS.getFilename( file.getParent() );\n\n          } else {\n            throw new RuntimeException( \"file [\" + ArgList[0] + \"] can not be found!\" );\n          }\n\n          return foldername;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call getParentFoldername throw an error : \" + 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 new RuntimeException( \"The function call getParentFoldername is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n","sourceCodeStart":2298,"sourceCodeEnd":2334,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2298-L2334","documentation":"getParentFoldername() wraps any IOException from VFS resolution or from file.getParent() into this RuntimeException, appending e.toString(). The argument was syntactically acceptable but the VFS layer failed to resolve or query it.","triggerScenarios":"Malformed VFS URI (bad scheme, unescaped characters); file.getParent() throwing IOException on some providers; remote VFS (SFTP/S3) unreachable or credentials failing mid-run.","commonSituations":"Windows backslash paths parsed as URI scheme; missing commons-vfs provider for a custom scheme; transient network failures during long-running transformations.","solutions":["Inspect the appended IOException text for the root cause.","Convert the path to a proper URI (forward slashes, escaped spaces) or use file:/// scheme.","Install the needed VFS plugin for the scheme; verify remote credentials/connectivity.","Add retry logic around the transformation or step for transient network errors.","Fall back to pure-JS string manipulation (substring(0, lastIndexOf('/'))) when only the path string is needed."],"exampleFix":"// before\nvar dir = getParentFoldername( 'sftp://user:pw@host/path/file.txt' ); // IOException if unreachable\n// after\ntry {\n  var dir = getParentFoldername( 'sftp://user:pw@host/path/file.txt' );\n} catch (e) {\n  var dir = filename.substring( 0, filename.lastIndexOf('/') );\n}","handlingStrategy":"try-catch","validationCode":"var uri = String(path).replace(/\\\\/g, '/');\nif (/^[A-Za-z]:/.test(uri)) { uri = 'file:///' + uri; }","typeGuard":"function isUriLike(v){ return typeof v === 'string' && /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(v); }","tryCatchPattern":"try { var dir = getParentFoldername(path); } catch (e) { Logger.logError('getParentFoldername IO failure: ' + e); var dir = String(path).substring(0, String(path).lastIndexOf('/')); }","preventionTips":["Normalize paths to VFS URI form before calling","Verify VFS plugins and remote credentials up front","Prefer plain string manipulation when only the path text is needed","Retry transformations on transient network backends"],"tags":["io-error","vfs","uri","javascript-step"],"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"}