{"record":{"id":"382ba56248b0e557","repo":"pentaho/pentaho-kettle","slug":"abstractfileerrorhandler-exception","errorCode":"AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile","errorMessage":"AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile","messagePattern":"AbstractFileErrorHandler\\.Exception\\.CouldNotCreateFileErrorHandlerForFile","errorType":"error_code","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/step/errorhandling/AbstractFileErrorHandler.java","lineNumber":125,"sourceCode":"      if ( outputStreamWriter != null ) {\n        return outputStreamWriter;\n      }\n      FileObject file =\n        getReplayFilename( destinationDirectory, processingFilename, dateString, fileExtension, source );\n      ResultFile resultFile =\n        new ResultFile( ResultFile.FILE_TYPE_GENERAL, file, baseStep.getTransMeta().getName(), baseStep\n          .getStepname() );\n      baseStep.addResultFile( resultFile );\n      try {\n        if ( isBlank( encoding ) ) {\n          outputStreamWriter = new OutputStreamWriter( KettleVFS.getInstance( DefaultBowl.getInstance() )\n                                                       .getOutputStream( file, false ) );\n        } else {\n          outputStreamWriter = new OutputStreamWriter( KettleVFS.getInstance( DefaultBowl.getInstance() )\n                                                       .getOutputStream( file, false ), encoding );\n        }\n      } catch ( Exception e ) {\n        throw new KettleException( BaseMessages.getString(\n          PKG, \"AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile\" )\n          + file.getName().getURI(), e );\n      }\n      writers.put( source, outputStreamWriter );\n      return outputStreamWriter;\n    } catch ( KettleFileException e ) {\n      throw new KettleException( BaseMessages.getString(\n        PKG, \"AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile\" ), e );\n    }\n  }\n\n  public void close() throws KettleException {\n    for ( Iterator<Writer> iter = writers.values().iterator(); iter.hasNext(); ) {\n      close( iter.next() );\n    }\n    writers = new HashMap<Object, Writer>();\n\n  }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/step/errorhandling/AbstractFileErrorHandler.java#L107-L143","documentation":"KettleException thrown by AbstractFileErrorHandler.getWriter() when creating the OutputStreamWriter for an error-handling file fails for a given file part. It wraps the underlying KettleFileException or IOException with a message identifying the error-lineage file URI.","triggerScenarios":"getWriter(source) called on first write for a part; KettleVFS.getOutputStream(file, false) or new OutputStreamWriter(...) throws — target directory doesn't exist, no write permission, invalid filename/URI, or (when encoding != null) unsupported charset name.","commonSituations":"Text file input error handling configured with an error directory that doesn't exist or isn't writable; bad 'encoding' value typed in the step dialog (e.g. 'utf-8 ' typo); read-only mounted error directory.","solutions":["Create the configured error-handling directory and grant the process write permission","Verify the charset/encoding string is a valid supported encoding (e.g. 'UTF-8')","Check the target file URI in the message for typos or invalid characters","Run the transformation/Kettle process under a user with access to the error directory"],"exampleFix":"// before: encoding typo\nhandler = new FileErrorHandlerContentLineNumber(..., \"utf_8\", ...)\n// after\nhandler = new FileErrorHandlerContentLineNumber(..., \"UTF-8\", ...)","handlingStrategy":"validation","validationCode":"import org.apache.commons.vfs2.FileObject;\n// Before enabling file error handling:\nFileObject errFile = fsManager.resolveFile(errorDirUri + \"/error.txt\");\nFileObject parent = errFile.getParent();\nif (parent == null || !parent.exists() || !parent.isWriteable()) {\n  throw new IllegalStateException(\"Error dir missing/unwritable: \" + errorDirUri);\n}\nif (encoding != null && !java.nio.charset.Charset.isSupported(encoding)) {\n  throw new IllegalStateException(\"Unsupported encoding: \" + encoding);\n}","typeGuard":null,"tryCatchPattern":"try {\n  errorHandler.handleLineError(lineNr, part);\n} catch (KettleException e) {\n  log.error(\"Error-lineage file unusable: \" + e.getMessage(), e);\n  // fail the transformation or route bad rows to a fallback table\n  throw e;\n}","preventionTips":["Create and chmod the error-handling directory before running the transformation","Use exact supported charset names ('UTF-8', not typos)","Test error handling with a deliberately bad row before production runs","Monitor disk space on the error directory volume"],"tags":["file-io","error-handling","vfs"],"backgroundTag":"file-open-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"}