{"record":{"id":"9d7a2bbb72137028","repo":"pentaho/pentaho-kettle","slug":"the-function-call-copyfile-throw-an-error","errorCode":null,"errorMessage":"The function call copyFile throw an error : ","messagePattern":"The function call copyFile throw an error : ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2056,"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 copy the file...\n              if ( ( destinationExists && overwrite ) || !destinationExists ) {\n                FileUtil.copyContent( fileSource, fileDestination );\n              }\n\n            }\n          } else {\n            throw new RuntimeException( \"file to copy [\" + ArgList[0] + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw new RuntimeException( \"The function call copyFile 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":2038,"sourceCodeEnd":2074,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2038-L2074","documentation":"copyFile() catches IOException from path resolution or FileUtil.copyContent and rethrows as 'The function call copyFile throw an error : ' + e.toString(). Unlike some sibling functions, the underlying IOException message is preserved, pointing at the real IO failure during resolve or copy.","triggerScenarios":"Calling copyFile(src, dest, overwrite) where an IOException occurs: malformed source/destination URI, destination unwritable, target directory missing, network filesystem error, or disk full during copyContent.","commonSituations":"Destination directory does not exist; no write permission on the destination; sftp/webdav destinations unreachable; malformed VFS URIs (backslashes, bad scheme); insufficient disk space on large copies.","solutions":["Read the appended e.toString() in the message to identify the real cause and fix that specific IO problem.","Ensure the destination directory exists (createFolder first) and is writable by the process user.","Validate both source and destination as proper VFS URIs (forward slashes, valid scheme).","Check free disk space and quota for large files.","For remote destinations, verify connectivity/credentials before running the copy."],"exampleFix":"// before\ncopyFile('file:///data/in.csv', 'file:///data/archive/in.csv', true); // archive dir missing\n// after\nif (!fileExists('file:///data/archive')) { createFolder('file:///data/archive'); }\ncopyFile('file:///data/in.csv', 'file:///data/archive/in.csv', true);","handlingStrategy":"try-catch","validationCode":"if (!fileExists(src)) throw new Error('missing source');\nif (!fileExists(destFolder)) createFolder(destFolder);","typeGuard":"function isVfsUri(p) { return typeof p === 'string' && (/^[a-z]+:\\/\\//.test(p) || p.startsWith('/')); }","tryCatchPattern":"try { copyFile(src, dest, true); } catch (e) { // e.toString() already carries the IOException; log and rethrow or fall back\n  throw e; }","preventionTips":["Create the destination directory before copying","Validate both URIs (scheme, separators)","Check disk space and remote connectivity for large/remote copies"],"tags":["file-io","copy","io-exception","vfs"],"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"}