pentaho/pentaho-kettle · error · KettleStepException

Error writing field content to file

Error message

Error writing field content to file

What it means

writeField converts one field value to its formatted bytes and writes it (with separators/enclosures) to the writer. Any failure in the conversion or write is wrapped in KettleStepException 'Error writing field content to file'.

Solutions

  1. Look at the cause to see which field failed; check its format/length/precision in the Fields tab
  2. Fix the offending value (null handling, format mask, trim type)
  3. Check output stream/disk health

Example fix

// before: field format '###,##' invalid
fieldMeta.setConversionMask( "###,##" );
// after
fieldMeta.setConversionMask( "#,##0.00" );
Defensive patterns

Strategy: try-catch

Validate before calling

// dry-run the value conversion per field
for ( int i = 0; i < outputMeta.size(); i++ ) { formatField( outputMeta.getValueMeta( i ), row[i] ); } // throws KettleValueException early

Try / catch

try { writeRow( row ); } catch ( KettleStepException e ) { logError( "Field write failed: " + e.getCause(), e ); putError( outputRowMeta, row, 1, e.getCause().getMessage(), "FieldWriteError", "TextFileOutput-06" ); }

Prevention

When it happens

Trigger: data.writer.write throws IO error, or byte formatting of the value (formatField/getValueMeta conversions, padding, enclosure logic) fails for a specific field value.

Common situations: Incompatible value/format mismatch (e.g. numeric format string invalid), disk full, stream closed after split.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java:655

          // Skip the enclosures, double them instead...
          int from = 0;
          for ( int i = 0; i < enclosures.size(); i++ ) {
            int position = enclosures.get( i );
            data.writer.write( str, from, position + data.binaryEnclosure.length - from );
            data.writer.write( data.binaryEnclosure ); // write enclosure a second time
            from = position + data.binaryEnclosure.length;
          }
          if ( from < str.length ) {
            data.writer.write( str, from, str.length - from );
          }
        }

        if ( writeEnclosures ) {
          data.writer.write( data.binaryEnclosure );
        }
      }
    } catch ( Exception e ) {
      throw new KettleStepException( "Error writing field content to file", e );
    }
  }

  private List<Integer> getEnclosurePositions( byte[] str ) {
    List<Integer> positions = null;
    if ( data.binaryEnclosure != null && data.binaryEnclosure.length > 0 ) {
      // +1 because otherwise we will not find it at the end
      for ( int i = 0, len = str.length - data.binaryEnclosure.length + 1; i < len; i++ ) {
        // verify if on position i there is an enclosure
        //
        boolean found = true;
        for ( int x = 0; found && x < data.binaryEnclosure.length; x++ ) {
          if ( str[ i + x ] != data.binaryEnclosure[ x ] ) {
            found = false;
          }
        }
        if ( found ) {
          if ( positions == null ) {

View on GitHub (pinned to f3058517a1)