{"record":{"id":"218ab6eb13ac56e4","repo":"pentaho/pentaho-kettle","slug":"the-function-call-movefile-throw-an-error-e-tostring","errorCode":null,"errorMessage":"The function call moveFile throw an error :  + e.toString()","messagePattern":"The function call moveFile 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":2501,"sourceCode":"            // Source file exists...\n            if ( fileSource.getType() == FileType.FILE ) {\n              // Great..source is a file ...\n              boolean overwrite = false;\n              if ( !ArgList[1].equals( null ) ) {\n                overwrite = (Boolean) ArgList[2];\n              }\n              boolean destinationExists = fileDestination.exists();\n              // Let's move the file...\n              if ( ( destinationExists && overwrite ) || !destinationExists ) {\n                fileSource.moveTo( fileDestination );\n              }\n\n            }\n          } else {\n            throw new RuntimeException( \"file to move [\" + ArgList[0] + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call moveFile throw an error : \" + e.toString() );\n        } finally {\n          if ( fileSource != null ) {\n            try {\n              fileSource.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n          if ( fileDestination != null ) {\n            try {\n              fileDestination.close();\n            } catch ( Exception e ) {\n              // Ignore errors\n            }\n          }\n        }\n\n      } else {","sourceCodeStart":2483,"sourceCodeEnd":2519,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2483-L2519","documentation":"This is moveFile's IOException handler: any filesystem/VFS error during the move (destination unwritable, directory missing, locked file, permission denied) is rethrown as a RuntimeException whose message concatenates e.toString(). The underlying exception class and message are preserved but the stack trace is lost.","triggerScenarios":"An IOException is raised by fileSource.moveTo(fileDestination) or by resolving file objects — destination directory does not exist, no write permission, file locked by another process, network share unreachable.","commonSituations":"Destination folder not created beforehand; running transformation as a service account lacking write rights on the target dir; moving files over SFTP when the connection drops; Windows file locks from another process holding the source open; message like 'The function call moveFile throw an error : org.apache.commons.vfs2.FileSystemException: ...'.","solutions":["Read the embedded e.toString() to get the real VFS FileSystemException and its file/reason","Create the destination directory before moving (e.g. via createParentFolder or an earlier step)","Check filesystem permissions for the user executing the transformation","Retry on transient network/SFTP failures; ensure no other process holds the source file open"],"exampleFix":"// before\nmoveFile(src, '/data/out/file.txt', true); // /data/out may not exist\n// after\nif (!folderExists('/data/out')) createFolder('/data/out');\nmoveFile(src, '/data/out/file.txt', true);","handlingStrategy":"try-catch","validationCode":"// best-effort pre-checks in script\nif (fileExists(src) && folderExists(dst.substring(0, dst.lastIndexOf('/')))) {\n  moveFile(src, dst, true);\n}","typeGuard":null,"tryCatchPattern":"try {\n  moveFile(src, dst, true);\n} catch (e) {\n  var cause = String(e.message); // contains underlying VFS exception toString()\n  Logger.logError('moveFile failed: ' + cause);\n  if (cause.indexOf('FileSystemException') >= 0) {\n    // permission/lock/network issue: alert or retry\n  }\n}","preventionTips":["Create the destination directory before moving","Check write permissions for the account running the transformation (service accounts often lack them)","Retry transient failures on network/SFTP mounts with a small delay","Ensure no other process holds the source file open (Windows locks)","Parse the embedded exception text — e.toString() preserves the VFS reason"],"tags":["javascript","scripting","file-io","ioexception"],"backgroundTag":"file-write-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"}