pentaho/pentaho-kettle · error · RuntimeException

folder [

Error message

folder [

What it means

The createFolder() script helper throws 'folder [name] already exist!' when KettleVFS reports the target path already exists, so creating the folder again is rejected. Note the message is emitted from the else-branch of the exists() check before any folder creation is attempted.

Solutions

  1. Check existence first with fileExists() and only call createFolder when it returns false.
  2. Use a unique folder name (timestamp/UUID suffix) for per-run directories.
  3. If reuse is fine, just verify the path exists and is a directory, then skip creation.
  4. Clean up or archive old run directories before re-running the transformation.

Example fix

// before
createFolder('/tmp/work');
// after
if (!fileExists('/tmp/work')) { createFolder('/tmp/work'); }
Defensive patterns

Strategy: validation

Validate before calling

if (!fileExists(path)) { createFolder(path); }

Type guard

function isNonEmptyString(s) { return typeof s === 'string' && s.trim().length > 0; }

Try / catch

try { createFolder(path); } catch (e) { if (String(e).indexOf('already exist') >= 0) { /* tolerate reuse */ } else { throw e; } }

Prevention

When it happens

Trigger: Calling createFolder('path') where fileObject.exists() is true — the directory (or even a file) at that path already exists from a previous run or step.

Common situations: Re-running a transformation that creates working directories without cleanup; two steps in the same transformation creating the same folder; a file (not folder) occupying the intended path; timestamped directory logic that collides within the same day/hour.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:2001

      }
    } catch ( Exception e ) {
      throw new RuntimeException( e.toString() );
    }
  }

  public static void createFolder( Bowl bowl, ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {

    try {
      if ( ArgList.length == 1 && !isNull( ArgList[0] ) && !isUndefined( ArgList[0] ) ) {
        FileObject fileObject = null;

        try {
          fileObject = KettleVFS.getInstance( bowl ).getFileObject( (String) ArgList[0] );
          if ( !fileObject.exists() ) {
            fileObject.createFolder();
          } else {
            throw new RuntimeException( "folder [" + ArgList[0] + "] already exist!" );
          }
        } catch ( IOException e ) {
          throw new RuntimeException( "The function call createFolder is not valid." );
        } finally {
          if ( fileObject != null ) {
            try {
              fileObject.close();
            } catch ( Exception e ) {
              // Ignore errors
            }
          }
        }

      } else {
        throw new RuntimeException( "The function call createFolder is not valid." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( e.toString() );

View on GitHub (pinned to f3058517a1)