{"record":{"id":"b3bfb22ed8fece57","repo":"pentaho/pentaho-kettle","slug":"error-writing-line","errorCode":null,"errorMessage":"Error writing line","messagePattern":"Error writing line","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java","lineNumber":505,"sourceCode":"         * Only write the fields specified!\n         */\n        for ( int i = 0; i < meta.getOutputFields().length; i++ ) {\n          if ( i > 0 && data.binarySeparator.length > 0 ) {\n            data.writer.write( data.binarySeparator );\n          }\n\n          ValueMetaInterface v = meta.getMetaWithFieldOptions()[ i ];\n          Object valueData = r[ data.fieldnrs[ i ] ];\n          writeField( v, valueData, data.binaryNullValue[ i ] );\n        }\n      }\n\n      data.writer.write( data.binaryNewline );\n\n      incrementLinesOutput();\n\n    } catch ( Exception e ) {\n      throw new KettleStepException( \"Error writing line\", e );\n    }\n  }\n\n  private byte[] formatField( ValueMetaInterface v, Object valueData ) throws KettleValueException {\n    if ( v.isString() ) {\n      if ( v.isStorageBinaryString() && v.getTrimType() == ValueMetaInterface.TRIM_TYPE_NONE && v.getLength() < 0\n          && Utils.isEmpty( v.getStringEncoding() ) ) {\n        return (byte[]) valueData;\n      } else {\n        String svalue = ( valueData instanceof String ) ? (String) valueData : v.getString( valueData );\n        return convertStringToBinaryString( v, Const.trimToType( svalue, v.getTrimType() ) );\n      }\n    } else {\n      return v.getBinaryString( valueData );\n    }\n  }\n\n  private byte[] convertStringToBinaryString( ValueMetaInterface v, String string ) throws KettleValueException {","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java#L487-L523","documentation":"TextFileOutput.writeRow serializes the formatted fields and writes the line plus binary newline to the writer. Any exception in that block (IO error, formatting failure, encoding problem) is wrapped in KettleStepException 'Error writing line'.","triggerScenarios":"data.writer.write() of the field bytes or binaryNewline throws: stream closed, disk full, or formatField throws KettleValueException for a field value.","commonSituations":"Disk full mid-transformation; file closed by 'split every N rows' logic race; incompatible field values producing formatting errors.","solutions":["Inspect the wrapped cause (getCause()) to find the real failure (IO vs value formatting)","Check disk space and output stream state","Validate field values/formats in the step's Fields tab (format, length, precision)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// validate field formats before the run\nfor ( TextFileField f : fields ) { if ( f.getFormat() != null ) checkFormatSupported( f.getFormat() ); }","typeGuard":null,"tryCatchPattern":"try { writeRow( row ); } catch ( KettleStepException e ) { Throwable cause = e.getCause(); logError( \"Write failed: \" + cause ); if ( cause instanceof IOException ) checkDiskAndStream(); }","preventionTips":["Validate field formats/lengths in the Fields tab","Monitor disk space and file handle usage","Handle nulls before formatting"],"tags":["kettle","pentaho","textfileoutput","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"}