{"record":{"id":"2378cfc73087eff6","repo":"pentaho/pentaho-kettle","slug":"the-function-call-copyfile-throw-an-error-2378cf","errorCode":null,"errorMessage":"The function call copyFile throw an error : ","messagePattern":"The function call copyFile 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":2145,"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 = Context.toBoolean( 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            Context.reportRuntimeError( \"file to copy [\" + Context.toString( ArgList[0] ) + \"] can not be found!\" );\n          }\n        } catch ( IOException e ) {\n          throw Context.reportRuntimeError( \"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":2127,"sourceCodeEnd":2163,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2127-L2163","documentation":"copyFile() throws this when the copy operation raises a java.io.IOException; the exception text is appended after the prefix. It means the source file was found but reading it or writing the destination failed. The message includes the underlying java.io exception, which is the key diagnostic.","triggerScenarios":"copyFile(src, dst) with an existing src but: destination is a directory or unwritable, destination parent missing, disk full, file locked, or VFS cannot open one of the two FileObjects.","commonSituations":"Copying onto a path that already exists as a directory; target volume full; network share dropped mid-copy; permission denied on the destination folder.","solutions":["Read the appended java exception text to pinpoint the failing side (source read vs destination write).","Verify the destination directory exists and is writable.","Ensure the destination path is a file path, not an existing directory.","Check free disk space and that neither file is locked by another process.","Ensure both src and dst are proper string paths/URIs."],"exampleFix":"// before\ncopyFile('/data/in.csv', '/data/backup'); // backup is a directory\n// after\ncopyFile('/data/in.csv', '/data/backup/in.csv');","handlingStrategy":"validation","validationCode":"var srcF = new java.io.File(src);\nvar dstF = new java.io.File(dst);\nif (!srcF.exists()) { throw new Error('src missing: ' + src); }\nif (dstF.isDirectory()) { throw new Error('dst is a directory: ' + dst); }\nvar parent = dstF.getParentFile();\nif (parent != null && !parent.exists()) { parent.mkdirs(); }","typeGuard":null,"tryCatchPattern":"try { copyFile(src, dst); } catch (e) { Logger.logError('copy failed: ' + e.message); }","preventionTips":["Ensure destination parent exists and is writable","Destination must be a file path, not a directory","Check disk space before large copies","Read the appended java exception text to find the failing side"],"tags":["javascript","pdi","ioexception","file-copy"],"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"}