{"record":{"id":"a1b64a9e449ebe14","repo":"pentaho/pentaho-kettle","slug":"error-opening-new-file-exception","errorCode":null,"errorMessage":"Error opening new file : {exception}","messagePattern":"Error opening new file : (.+?)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java","lineNumber":92,"sourceCode":"    super( stepMeta, stepDataInterface, copyNr, transMeta, trans );\n  }\n\n  private void initFieldNumbers( RowMetaInterface outputRowMeta, TextFileField[] outputFields ) throws KettleException {\n    data.fieldnrs = new int[outputFields.length];\n    for ( int i = 0; i < outputFields.length; i++ ) {\n      data.fieldnrs[i] = outputRowMeta.indexOfValue( outputFields[i].getName() );\n      if ( data.fieldnrs[i] < 0 ) {\n        throw new KettleStepException( \"Field [\" + outputFields[i].getName()\n          + \"] couldn't be found in the input stream!\" );\n      }\n    }\n  }\n\n  public boolean isFileExists( String filename ) throws KettleException {\n    try {\n      return getFileObject( filename, getTransMeta() ).exists();\n    } catch ( Exception e ) {\n      throw new KettleException( \"Error opening new file : \" + e.toString() );\n    }\n  }\n\n  private CompressionProvider getCompressionProvider() throws KettleException {\n    String compressionType = Const.NVL( meta.getFileCompression(), FILE_COMPRESSION_TYPE_NONE );\n\n    CompressionProvider compressionProvider = CompressionProviderFactory.getInstance().getCompressionProviderByName( compressionType );\n\n    if ( compressionProvider == null ) {\n      throw new KettleException( \"No compression provider found with name = \" + compressionType );\n    }\n\n    if ( !compressionProvider.supportsOutput() ) {\n      throw new KettleException( \"Compression provider \" + compressionType + \" does not support output streams!\" );\n    }\n    return compressionProvider;\n  }\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/textfileoutput/TextFileOutput.java#L74-L110","documentation":"isFileExists wraps any failure from the VFS file object's exists() check (getFileObject(filename, getTransMeta()).exists()) in a KettleException with this message. It means the file system layer could not even probe the file, not that the file exists or not. The underlying VFS/KettleVFS exception is flattened into e.toString(), so diagnose from that string.","triggerScenarios":"Calling isFileExists (directly or via initFileStreamWriter/isWriteHeader) with a filename that resolves to an invalid/unreachable VFS URI, a permission-restricted path, or a malformed variable-expanded path (e.g. ${Internal.Transformation.Filename.Directory} unset).","commonSituations":"Output directory does not exist on a remote VFS (SFTP/HTTP) provider; environment variable in the file path not set at runtime; permission denied on the target directory; invalid Windows/UNC path syntax after variable substitution.","solutions":["Check e.toString() in the message to identify the underlying VFS error (malformed URI, permission, unknown host)","Verify the fully substituted filename is a valid path (resolve variables before the run)","Ensure the output directory exists and the process user has write permission","Test the path scheme (file:, sftp:, etc.) is supported by the configured VFS provider"],"exampleFix":"// before\nString filename = \"${OUT_DIR}/export.txt\"; // OUT_DIR unset -> invalid VFS url\n// after\nString filename = variables.getVariable( \"OUT_DIR\", \"/data/out\" ) + \"/export.txt\";","handlingStrategy":"validation","validationCode":"String resolved = space.environmentSubstitute( filename );\nif ( resolved == null || resolved.trim().isEmpty() ) {\n  throw new IllegalArgumentException( \"Output filename resolves to empty\" );\n}\nFile dir = new File( new File( resolved ).getParent() );\nif ( !dir.isDirectory() || !dir.canWrite() ) {\n  throw new IllegalArgumentException( \"Output dir missing or unwritable: \" + dir );\n}","typeGuard":null,"tryCatchPattern":"try {\n  boolean exists = isFileExists( filename );\n} catch ( KettleException e ) {\n  logError( \"Cannot probe file \" + filename + \": \" + e.getMessage(), e );\n  // fall back to treating the file as absent or fail fast based on policy\n}","preventionTips":["Verify all variables in the file path are defined before running the transformation","Ensure target directories exist and are writable by the service account","Test VFS schemes (sftp:, etc.) connectivity out-of-band before batch runs"],"tags":["filesystem","vfs","io","kettle"],"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"}