{"record":{"id":"7bb6e415dbaa8fdc","repo":"pentaho/pentaho-kettle","slug":"the-function-call-copyfile-is-not-valid-7bb6e4","errorCode":null,"errorMessage":"The function call copyFile is not valid.","messagePattern":"The function call copyFile is not valid\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":2610,"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 Context.reportRuntimeError( \"The function call copyFile is not valid.\" );\n      }\n    } catch ( Exception e ) {\n      throw Context.reportRuntimeError( e.toString() );\n    }\n  }\n\n  public static String execProcess( Context actualContext, Scriptable actualObject, Object[] ArgList,\n    Function FunctionContext ) {\n    String retval = null;\n    if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {\n      Process processrun = null;\n      try {\n\n        String ligne = \"\";\n        StringBuilder buffer = new StringBuilder();\n        processrun = Runtime.getRuntime().exec( Context.toString( ArgList[0] ) );\n\n        // Get process response","sourceCodeStart":2592,"sourceCodeEnd":2628,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L2592-L2628","documentation":"copyFile(source, target) copies a file; it validates its signature the same way as the other helpers. When the argument count/type contract is not met (anything other than the expected two string path arguments pattern), it throws this generic 'not valid' runtime error instead of performing the copy.","triggerScenarios":"copyFile() with missing arguments, a single argument, more than two arguments, or arguments that are not file-path strings in the Modified Java Script Value step.","commonSituations":"Undefined variables due to empty upstream fields; swapping argument order expectations; calling with File objects where strings were expected in a custom Kettle version; typos in variable names leaving null args.","solutions":["Call with exactly two string paths: copyFile('/src/a.txt', '/dst/a.txt').","Coerce/validate arguments: if (src != null && dst != null) copyFile(src.toString(), dst.toString()).","Log the argument values right before the call to spot nulls.","Pre-check the source exists to get the clearer dedicated error rather than the generic one where applicable."],"exampleFix":"// before\nvar f = copyFile(srcVar); // missing target\n// after\nif (srcVar != null && dstVar != null) { var f = copyFile(srcVar.toString(), dstVar.toString()); }","handlingStrategy":"validation","validationCode":"function safeCopy(s, d) { if (s == null || d == null || typeof s !== 'string' || typeof d !== 'string') return false; if (!new java.io.File(s).exists()) return false; try { copyFile(s, d); return true; } catch (e) { return false; } }","typeGuard":"function areTwoPaths(a, b) { return typeof a === 'string' && typeof b === 'string' && a.length > 0 && b.length > 0; }","tryCatchPattern":"try { copyFile(src, dst); } catch (e) { Logger.LogError('copyFile invalid/failed: ' + e.message); }","preventionTips":["Pass exactly two string path arguments","Coerce upstream variables with .toString()","Null-check before calling","Verify source exists to get clearer diagnostics"],"tags":["javascript","scripting","argument-validation","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"}