{"record":{"id":"25974453d2fdf269","repo":"pentaho/pentaho-kettle","slug":"the-function-call-isfolder-throw-an-error-e-tostring","errorCode":null,"errorMessage":"The function call isFolder throw an error :  + e.toString()","messagePattern":"The function call isFolder 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":2192,"sourceCode":"        }\n        FileObject file = null;\n\n        try {\n          // Source file\n          file = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );\n          boolean isafolder = false;\n          if ( file.exists() ) {\n            if ( file.getType().equals( FileType.FOLDER ) ) {\n              isafolder = true;\n            } else {\n              throw new RuntimeException( \"[\" + ArgList[0] + \"] is not a folder!\" );\n            }\n          } else {\n            throw new RuntimeException( \"folder [\" + ArgList[0] + \"] can not be found!\" );\n          }\n          return isafolder;\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call isFolder 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 isFolder is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n","sourceCodeStart":2174,"sourceCodeEnd":2210,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2174-L2210","documentation":"This is the IOException handler of ScriptAddedFunctions.isFolder(): any failure while resolving or reading the VFS FileObject (KettleVFS.getFileObject or file.exists()/getType()) is re-thrown as RuntimeException with the prefix 'The function call isFolder throw an error : ' followed by e.toString(). It signals an I/O-level problem (not a logical 'folder missing' condition) while accessing the path.","triggerScenarios":"Calling isFolder(path) when KettleVFS.getFileObject or exists()/getType() throws IOException — unreachable remote host, invalid URI/scheme, network interruption, or filesystem permission/IO errors.","commonSituations":"Malformed VFS URLs (bad scheme like 'file:/path with spaces' unescaped); SFTP/HTTP VFS servers down or credentials changed; network partitions during a long-running transformation; disk errors.","solutions":["Read the appended e.toString() to identify the underlying IOException cause (connection refused, unknown host, malformed URI, etc.).","Validate the VFS URL format/scheme and encode special characters in the path before calling.","Test connectivity/credentials to the remote filesystem; retry once connectivity is restored.","Run the step with more verbose logging or catch the RuntimeException in the JavaScript step to inspect the message.","Fix root cause rather than swallowing: e.g. correct the VFS provider configuration."],"exampleFix":"// before\nvar ok = isFolder( someUserUrl ); // may throw: The function call isFolder throw an error : ...\n// after\ntry {\n  var ok = isFolder( encodeURI( someUserUrl ) );\n} catch ( ex ) {\n  Logger.logError( \"isFolder IO problem: \" + ex.message );\n}","handlingStrategy":"try-catch","validationCode":"// validate the VFS URL shape before calling\nif ( /^[a-z]+:\\/\\//.test(p) || p.indexOf(\"/\") === 0 ) { /* plausible path */ }","typeGuard":"function isValidVfsPath(p) { return typeof p === \"string\" && p.trim().length > 0 && !/[\"<>|]/.test(p); }","tryCatchPattern":"try { ok = isFolder(p); } catch (e) { var m = String(e.message); if (m.indexOf(\"throw an error\") >= 0) { Logger.logError(\"VFS IO: \" + m); /* retry or fail row */ } }","preventionTips":["Encode spaces and special characters in VFS URLs.","Monitor remote filesystem availability and credentials before long runs.","Add retry logic for transient network failures.","Test the exact VFS scheme (sftp://, http://, file://) in isolation first."],"tags":["java","vfs","io","network","wrapped-exception"],"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"}