{"record":{"id":"1e9c718d48d69ae9","repo":"pentaho/pentaho-kettle","slug":"the-function-call-copyfile-is-not-valid","errorCode":null,"errorMessage":"The function call copyFile is not valid.","messagePattern":"The function call copyFile is not valid\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java","lineNumber":2520,"sourceCode":"        } 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 {\n        throw new RuntimeException( \"The function call copyFile is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw new RuntimeException( e.toString() );\n    }\n  }\n\n}\n","sourceCodeStart":2502,"sourceCodeEnd":2528,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java#L2502-L2528","documentation":"copyFile(source, destination, overwrite) is a scripting function that duplicates a file via KettleVFS. This RuntimeException signals the call itself is malformed rather than an I/O failure: the function requires exactly 3 arguments — source path, destination path, and a boolean overwrite flag — and this message is thrown when that contract (including non-null source) is not met.","triggerScenarios":"Calling copyFile with fewer or more than 3 arguments, or with a null/undefined source path — e.g. copyFile(src, dst) omitting the overwrite flag, or a variable holding the source path being undefined.","commonSituations":"Older examples calling copyFile(src, dst) without the overwrite boolean; the overwrite argument accidentally removed in a refactor; a null path variable produced by an empty upstream field; confusing this with java.nio Files.copy signatures.","solutions":["Call copyFile with exactly 3 arguments: copyFile(src, dst, trueOrFalse)","Add the missing overwrite boolean (true to replace an existing destination, false otherwise)","Ensure the source path variable is non-null and non-undefined before calling","If you truly need a 2-arg copy, write a small wrapper function defaulting overwrite to false"],"exampleFix":"// before\ncopyFile(srcPath, dstPath);\n// after\ncopyFile(srcPath, dstPath, true); // explicit overwrite flag","handlingStrategy":"validation","validationCode":"function safeCopy(src, dst, overwrite) {\n  if (src == null || dst == null) throw new Error('copyFile needs src and dst');\n  if (typeof overwrite !== 'boolean') overwrite = false;\n  copyFile(src, dst, overwrite);\n}","typeGuard":"function canCopy(src, dst, ow) { return typeof src === 'string' && typeof dst === 'string' && typeof ow === 'boolean'; }","tryCatchPattern":"try {\n  copyFile(src, dst, false);\n} catch (e) {\n  if (String(e.message).indexOf('copyFile is not valid') >= 0) {\n    Logger.logError('copyFile requires 3 args: src, dst, overwrite');\n  } else { throw e; }\n}","preventionTips":["Always pass the 3rd overwrite argument explicitly","Verify the source path variable is populated before the script step","Do not confuse with java.nio Files.copy(...) signatures","Wrap in a helper that supplies a default overwrite value","Use fileExists(src) first to separate arity errors from file-not-found errors"],"tags":["javascript","scripting","argument-count","file-io"],"backgroundTag":"missing-required-argument","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"}