{"record":{"id":"d47460867b772f28","repo":"pentaho/pentaho-kettle","slug":"error-writing-field-content-to-file","errorCode":null,"errorMessage":"Error writing field content to file","messagePattern":"Error writing field content to file","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java","lineNumber":655,"sourceCode":"          // Skip the enclosures, double them instead...\n          int from = 0;\n          for ( int i = 0; i < enclosures.size(); i++ ) {\n            int position = enclosures.get( i );\n            data.writer.write( str, from, position + data.binaryEnclosure.length - from );\n            data.writer.write( data.binaryEnclosure ); // write enclosure a second time\n            from = position + data.binaryEnclosure.length;\n          }\n          if ( from < str.length ) {\n            data.writer.write( str, from, str.length - from );\n          }\n        }\n\n        if ( writeEnclosures ) {\n          data.writer.write( data.binaryEnclosure );\n        }\n      }\n    } catch ( Exception e ) {\n      throw new KettleStepException( \"Error writing field content to file\", e );\n    }\n  }\n\n  private List<Integer> getEnclosurePositions( byte[] str ) {\n    List<Integer> positions = null;\n    if ( data.binaryEnclosure != null && data.binaryEnclosure.length > 0 ) {\n      // +1 because otherwise we will not find it at the end\n      for ( int i = 0, len = str.length - data.binaryEnclosure.length + 1; i < len; i++ ) {\n        // verify if on position i there is an enclosure\n        //\n        boolean found = true;\n        for ( int x = 0; found && x < data.binaryEnclosure.length; x++ ) {\n          if ( str[ i + x ] != data.binaryEnclosure[ x ] ) {\n            found = false;\n          }\n        }\n        if ( found ) {\n          if ( positions == null ) {","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java#L637-L673","documentation":"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'.","triggerScenarios":"data.writer.write throws IO error, or byte formatting of the value (formatField/getValueMeta conversions, padding, enclosure logic) fails for a specific field value.","commonSituations":"Incompatible value/format mismatch (e.g. numeric format string invalid), disk full, stream closed after split.","solutions":["Look at the cause to see which field failed; check its format/length/precision in the Fields tab","Fix the offending value (null handling, format mask, trim type)","Check output stream/disk health"],"exampleFix":"// before: field format '###,##' invalid\nfieldMeta.setConversionMask( \"###,##\" );\n// after\nfieldMeta.setConversionMask( \"#,##0.00\" );","handlingStrategy":"try-catch","validationCode":"// dry-run the value conversion per field\nfor ( int i = 0; i < outputMeta.size(); i++ ) { formatField( outputMeta.getValueMeta( i ), row[i] ); } // throws KettleValueException early","typeGuard":null,"tryCatchPattern":"try { writeRow( row ); } catch ( KettleStepException e ) { logError( \"Field write failed: \" + e.getCause(), e ); putError( outputRowMeta, row, 1, e.getCause().getMessage(), \"FieldWriteError\", \"TextFileOutput-06\" ); }","preventionTips":["Set correct conversion masks per field","Handle null values explicitly","Test transformation on sample data before full run"],"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"}