pentaho/pentaho-kettle · error

The function call copyFile is not valid.

Error message

The function call copyFile is not valid.

What it means

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.

Solutions

  1. Call with exactly two string paths: copyFile('/src/a.txt', '/dst/a.txt').
  2. Coerce/validate arguments: if (src != null && dst != null) copyFile(src.toString(), dst.toString()).
  3. Log the argument values right before the call to spot nulls.
  4. Pre-check the source exists to get the clearer dedicated error rather than the generic one where applicable.

Example fix

// before
var f = copyFile(srcVar); // missing target
// after
if (srcVar != null && dstVar != null) { var f = copyFile(srcVar.toString(), dstVar.toString()); }
Defensive patterns

Strategy: validation

Validate before calling

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; } }

Type guard

function areTwoPaths(a, b) { return typeof a === 'string' && typeof b === 'string' && a.length > 0 && b.length > 0; }

Try / catch

try { copyFile(src, dst); } catch (e) { Logger.LogError('copyFile invalid/failed: ' + e.message); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/7bb6e415dbaa8fdc. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java:2610

        } finally {
          if ( fileSource != null ) {
            try {
              fileSource.close();
            } catch ( Exception e ) {
              // Ignore errors
            }
          }
          if ( fileDestination != null ) {
            try {
              fileDestination.close();
            } catch ( Exception e ) {
              // Ignore errors
            }
          }
        }

      } else {
        throw Context.reportRuntimeError( "The function call copyFile is not valid." );
      }
    } catch ( Exception e ) {
      throw Context.reportRuntimeError( e.toString() );
    }
  }

  public static String execProcess( Context actualContext, Scriptable actualObject, Object[] ArgList,
    Function FunctionContext ) {
    String retval = null;
    if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
      Process processrun = null;
      try {

        String ligne = "";
        StringBuilder buffer = new StringBuilder();
        processrun = Runtime.getRuntime().exec( Context.toString( ArgList[0] ) );

        // Get process response

View on GitHub (pinned to f3058517a1)