pentaho/pentaho-kettle · error · KettleException

Error writing field (posX,posY) (logged), KettleException(…

Error message

Error writing field (posX,posY) (logged), KettleException( e )

What it means

ExcelWriterStep.writeField() catches any exception thrown while writing a single field into a cell (POI cell write, data formatting, style application). It logs the field position (posX,posY), the stack trace, and rethrows as a KettleException to abort the transformation.

Solutions

  1. Check the stack trace logged via Const.getStackTracker to find the root cause
  2. Verify the field's value metadata (Data meta) matches the actual incoming value type
  3. For large workbooks, reduce distinct cell formats or switch to XLSX (XSSF) to avoid style exhaustion
  4. If caused by a closed stream, ensure the output file is not closed before writeNextLine completes

Example fix

// before: writing raw object may fail formatting
step.writeField(fieldName, vMeta, value, xlsRow, posX, null, -1, false);
// after: pre-format to a compatible type
if (value instanceof byte[]) { value = new String((byte[]) value, StandardCharsets.UTF_8); }
step.writeField(fieldName, vMeta, value, xlsRow, posX, null, -1, false);
Defensive patterns

Strategy: try-catch

Validate before calling

// Java (calling step config check)
for (ExcelWriterStepField f : meta.getOutputFields()) {
  if (f.getName() == null || f.getName().isEmpty()) throw new IllegalArgumentException("Field name required");
}

Try / catch

try { writer.writeField(name, vMeta, value, row, pos, null, -1, true); }
catch (KettleException e) {
  logError("Field write failed at " + pos + ": " + e.getCause(), e);
  setErrors(1);
}

Prevention

When it happens

Trigger: Any Exception during cell creation/writing in writeField: unsupported value type for the field's value meta, POI cell style exhaustion, invalid date/number conversion, or an underlying IOException writing to the sheet.

Common situations: Writing a field whose value cannot be formatted by the chosen value metadata (e.g. binary field to a string cell); exceeding the 64000 cell styles limit in HSSF; writing to a closed workbook stream.

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/6b126ee9f841aff7. Report an issue: GitHub.

Appendix: source

Thrown at plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java:593

              cell.setCellValue( vMeta.getNumber( v ) );
            } else if ( !meta.isRetainNullValues() ) {
              cell.setCellValue( "" );
            }
            break;
          default:
            // fallthrough: output the data value as a string
            if ( v != null ) {
              cell.setCellValue( vMeta.getString( v ) );
            } else if ( !meta.isRetainNullValues() ) {
              cell.setCellValue( "" );
            }
            break;
        }
      }
    } catch ( Exception e ) {
      logError( "Error writing field (" + data.posX + "," + data.posY + ") : " + e.toString() );
      logError( Const.getStackTracker( e ) );
      throw new KettleException( e );
    }
  }

  /**
   * Set specified cell format
   *
   * @param excelFieldFormat
   *          the specified format
   * @param cell
   *          the cell to set up format
   */
  private void setDataFormat( String excelFieldFormat, Cell cell ) {
    if ( log.isDebug() ) {
      logDebug( BaseMessages.getString( PKG, "ExcelWriterStep.Log.SetDataFormat", excelFieldFormat,
        CellReference.convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
    }

    DataFormat format = data.wb.createDataFormat();

View on GitHub (pinned to f3058517a1)