pentaho/pentaho-kettle · error · KettleException

Error retrieving discardfile string

Error message

Error retrieving discardfile string

What it means

When a discard file is configured, createCommandLine resolves it via VFS and appends discard='<path>'. A KettleFileException while resolving or reading the filename is wrapped and rethrown as this KettleException.

Solutions

  1. Fix the discard file path in the step dialog; ensure the directory exists and is writable.
  2. Define any environment variables used in the path.
  3. Use an absolute path or valid VFS URL.
  4. Clear the discard file field if it is not needed (error only fires when a value is set).

Example fix

// before
discard file = ${DISCARD_DIR}/load.dsc
// after
discard file = /tmp/orabulk/load.dsc
Defensive patterns

Strategy: validation

Validate before calling

// Java: pre-check optional discard file path
String dsc = meta.getDiscardFile();
if (dsc != null) {
  String resolved = transMeta.environmentSubstitute(dsc);
  File dir = new File(resolved).getAbsoluteFile().getParentFile();
  if (!dir.isDirectory() || !dir.canWrite()) {
    throw new IllegalStateException("Discard-file directory missing/unwritable: " + dir);
  }
}

Try / catch

try {
  trans.execute(null);
} catch (KettleException e) {
  if (String.valueOf(e.getMessage()).contains("Error retrieving discardfile")) {
    // fix or clear the discard file field
  }
}

Prevention

When it happens

Trigger: meta.getDiscardFile() is non-null but getFileObject(meta.getDiscardFile(), transMeta) or getFilename throws KettleFileException during createCommandLine (execute).

Common situations: Discard file path has an undefined variable; target directory does not exist; path scheme typo; relative path invalid on the host executing the transformation.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at plugins/oracle-bulk-loader/impl/src/main/java/org/pentaho/di/trans/steps/orabulkloader/OraBulkLoader.java:415

        sb.append( " bad=\'" );
        sb.append( getFilename( fileObject ) );
        sb.append( "\'" );
      } catch ( KettleFileException ex ) {
        throw new KettleException( "Error retrieving badfile string", ex );
      }
    }

    if ( meta.getDiscardFile() != null ) {
      try {
        FileObject fileObject =
          getFileObject( meta.getDiscardFile(), getTransMeta() );

        sb.append( " discard=\'" );
        sb.append( getFilename( fileObject ) );
        sb.append( "\'" );
      } catch ( KettleFileException ex ) {
        throw new KettleException( "Error retrieving discardfile string", ex );
      }
    }

    DatabaseMeta dm = meta.getDatabaseMeta();
    if ( dm != null ) {
      String user = Const.NVL( dm.getUsername(), "" );
      String pass =
        Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" );
      if ( !password ) {
        pass = "******";
      }
      String dns = Const.NVL( dm.getDatabaseName(), "" );
      sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append(
        environmentSubstitute( pass ) ).append( "@" );

      String overrideName = meta.getDbNameOverride();
      if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) {
        sb.append( environmentSubstitute( dns ) );

View on GitHub (pinned to f3058517a1)