{"record":{"id":"ce3806935dc3e198","repo":"pentaho/pentaho-kettle","slug":"file-to-copy","errorCode":null,"errorMessage":"file to copy [","messagePattern":"file to copy \\[","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2053,"sourceCode":"          // Destination filename\n          fileDestination = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[1] );\n          if ( fileSource.exists() ) {\n            // 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          }","sourceCodeStart":2035,"sourceCodeEnd":2071,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2035-L2071","documentation":"The copyFile() script helper throws 'file to copy [name] can not be found!' when the SOURCE file resolved via KettleVFS does not exist. The existence check happens before any copying; destination checks and overwrite logic are never reached.","triggerScenarios":"Calling copyFile(src, dest, overwrite) where src does not exist: wrong path, file not yet produced by an earlier step, relative path resolving against an unexpected working directory, or case mismatch on Linux.","commonSituations":"Copy step runs before the producing step/transform finished (ordering problem); typos in the source path; the previous run's cleanup deleted the file; expected input file missing from a watched directory.","solutions":["Check fileExists(src) before calling copyFile and handle absence explicitly.","Fix the source path (absolute path, correct casing and separators).","Re-order the transformation/job so the source file is created before the copy runs.","Verify any earlier 'Move/Delete' or cleanup steps are not removing the file prematurely."],"exampleFix":"// before\ncopyFile('data/in.csv', 'data/backup.csv', true); // in.csv not produced yet\n// after\nif (fileExists('data/in.csv')) { copyFile('data/in.csv', 'data/backup.csv', true); } else { throw new Error('input missing'); }","handlingStrategy":"validation","validationCode":"if (!fileExists(src)) { throw new Error('source file missing: ' + src); }\ncopyFile(src, dest, true);","typeGuard":"function isNonEmptyString(s) { return typeof s === 'string' && s.trim().length > 0; }","tryCatchPattern":"try { copyFile(src, dest, true); } catch (e) { if (String(e).indexOf('can not be found') >= 0) { /* handle missing input */ } else { throw e; } }","preventionTips":["Check source existence before copying","Order steps so producers run before copiers","Use absolute, OS-correct paths"],"tags":["file-io","copy","file-not-found","vfs"],"backgroundTag":"file-not-found","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"}