{"record":{"id":"8b40d4dec1b51617","repo":"pentaho/pentaho-kettle","slug":"error-writing-line-e-tostring-logged-kettleexception-e","errorCode":null,"errorMessage":"Error writing line :\" + e.toString() (logged), KettleException( e )","messagePattern":"Error writing line :\" \\+ e\\.toString\\(\\) \\(logged\\), KettleException\\( e \\)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java","lineNumber":386,"sourceCode":"          writeField( r[i], data.inputRowMeta.getValueMeta( i ), null, xlsRow, data.posX++, r, i, false );\n        }\n      } else {\n        /*\n         * Only write the fields specified!\n         */\n        for ( int i = 0; i < meta.getOutputFields().length; i++ ) {\n          Object v = r[data.fieldnrs[i]];\n          writeField( v, data.inputRowMeta.getValueMeta( data.fieldnrs[i] ), meta.getOutputFields()[i], xlsRow,\n            data.posX++, r, i, false );\n        }\n\n      }\n      // go to the next line\n      data.posX = data.startingCol;\n      data.posY++;\n    } catch ( Exception e ) {\n      logError( \"Error writing line :\" + e.toString() );\n      throw new KettleException( e );\n    }\n  }\n\n  private Comment createCellComment( String author, String comment ) {\n    // comments only supported for XLSX\n    if ( data.sheet instanceof XSSFSheet ) {\n      CreationHelper factory = data.wb.getCreationHelper();\n      Drawing<?> drawing = data.sheet.createDrawingPatriarch();\n\n      ClientAnchor anchor = factory.createClientAnchor();\n      Comment cmt = drawing.createCellComment( anchor );\n      RichTextString str = factory.createRichTextString( comment );\n      cmt.setString( str );\n      cmt.setAuthor( author );\n      return cmt;\n    }\n    return null;\n  }","sourceCodeStart":368,"sourceCodeEnd":404,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/excelwriter/ExcelWriterStep.java#L368-L404","documentation":"ExcelWriterStep.writeNextLine catches any exception thrown while writing a row of data to the sheet, logs 'Error writing line :<exception>', and rethrows it as a KettleException to fail the step. It means cell/sheet write operations for the current input row failed.","triggerScenarios":"writeNextLine() throws while creating/writing cells into data.sheet (e.g. invalid cell type/value, sheet write error, POI internal failure) for the current row; posX/posY advance only on success.","commonSituations":"Field values incompatible with the chosen Excel format (e.g. oversized strings, invalid formula content); unsupported cell comment/content on the current sheet type; POI limitations with the target workbook (XLS vs XLSX features); extremely wide rows exceeding column limits.","solutions":["Read the logged 'Error writing line :...' entry — it contains the underlying exception with row details.","Check the input row's field values and types against the step's field mapping (content/types).","If formulas are enabled, verify formula strings are valid Excel syntax.","For XLS output, confirm no XLSX-only features (e.g. cell comments, >65536 rows, >256 columns) are used.","Log or preview the failing row (add a 'Get rows' count / log row) to identify the offending data."],"exampleFix":"// before: null field value written as-is causes POI failure\nsheet.addCell( new jxl.write.Number( col, row, numericValue ) );\n// after: guard conversions\nif ( value == null ) {\n  sheet.addCell( new jxl.write.Blank( col, row ) );\n} else {\n  sheet.addCell( new jxl.write.Number( col, row, numericValue ) );\n}","handlingStrategy":"validation","validationCode":"// before running, validate the row fields written to Excel\nrowMeta.getFieldNames(); // confirm mapping matches input\nif ( value == null || String.valueOf( value ).length() > 32767 ) {\n  throw new IllegalArgumentException( \"Cell content exceeds Excel limit or is null\" );\n}","typeGuard":"boolean isExcelWritable( Object v ) { return v != null && !( v instanceof Double && !Double.isFinite( (Double) v ) ); }","tryCatchPattern":"try { writeNextLine( row ); } catch ( KettleException e ) { logError( \"Failed on row \" + rowNum + \": \" + e.getMessage(), e ); setErrors( 1 ); }","preventionTips":["Reject/blank null and non-finite numeric values before they reach the sheet.","Match XLS vs XLSX features to the selected output format (comments are XLSX-only).","Keep rows within Excel limits (65536 rows / 256 cols for XLS).","Validate formula strings when formula evaluation is enabled."],"tags":["pentaho-kettle","excel-writer","poi","row-write"],"backgroundTag":"file-write-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}