{"record":{"id":"fa222844c136d803","repo":"pentaho/pentaho-kettle","slug":"unable-to-add-filename-to-the-result","errorCode":null,"errorMessage":"Unable to add filename to the result","messagePattern":"Unable to add filename to the result","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/exceloutput/ExcelOutput.java","lineNumber":748,"sourceCode":"          stopAll();\n        }\n      } else {\n        return true;\n      }\n    }\n    return false;\n  }\n\n  private void addFilenameToResult() throws KettleException {\n    try {\n      if ( meta.isAddToResultFiles() ) {\n        // Add this to the result file names...\n        ResultFile resultFile =  new ResultFile( ResultFile.FILE_TYPE_GENERAL, data.file, getTransMeta().getName(), getStepname() );\n        resultFile.setComment( \"This file was created with an Excel output step by Pentaho Data Integration\" );\n        addResultFile( resultFile );\n      }\n    } catch ( Exception e ) {\n      throw new KettleException( \"Unable to add filename to the result\", e );\n    }\n  }\n\n  @Override\n  public void dispose( StepMetaInterface smi, StepDataInterface sdi ) {\n    meta = (ExcelOutputMeta) smi;\n    data = (ExcelOutputData) sdi;\n\n    if ( data.oneFileOpened ) {\n      closeFile();\n    }\n    if ( data.file != null ) {\n      try {\n        data.file.close();\n        data.file = null;\n      } catch ( Exception e ) {\n        logDetailed( BaseMessages.getString( PKG, \"ExcelOutput.Log.UnableToCloseFileDuringDispose\", data.file.getPublicURIString() ), e );\n      }","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/excel/core/src/main/java/org/pentaho/di/trans/steps/exceloutput/ExcelOutput.java#L730-L766","documentation":"ExcelOutput wraps any failure while registering the generated Excel file into the transformation's result-file list in this KettleException. After successfully writing and closing a file, addFilenameToResult creates a ResultFile and calls addResultFile; any exception there (VFS, metadata access, comment handling) is wrapped so the step fails with a uniform message.","triggerScenarios":"addFilenameToResult() throws when constructing the ResultFile or calling addResultFile() raises an exception — e.g. getTransMeta().getName() or VFS-backed data.file operations fail, or the underlying file object has been closed/disposed before this runs.","commonSituations":"Transformation metadata unavailable mid-execution; the VFS file handle is stale after write errors; unusual filenames/paths that break VFS resolution; failures during clustered execution where the result-files collection is in an unexpected state.","solutions":["Inspect the wrapped cause exception (e.getCause()) — the message itself is generic; the real failure is inside it.","Verify the output file was fully written and the FileObject (data.file) is still valid/open when the step finishes.","Check transformation name and step name are set and the step runs inside a normal Trans execution context.","If the cause is VFS-related, confirm the output path is accessible and not a transient/unmounted location.","Update PDI if the cause is a known NPE in result-file handling; check the wrapped stack trace against release notes."],"exampleFix":"// before: cause swallowed by wrapper\nthrow new KettleException( \"Unable to add filename to the result\", e );\n// after: guard and log cause before wrapping\nif ( data.file != null && data.file.exists() ) {\n  ResultFile resultFile = new ResultFile( ResultFile.FILE_TYPE_GENERAL, data.file, getTransMeta().getName(), getStepname() );\n  addResultFile( resultFile );\n} else {\n  logError( \"Output file missing, not adding to result: \" + data.realFilename );\n}","handlingStrategy":"try-catch","validationCode":"if ( data.file != null && data.file.exists() ) { /* safe to add to result */ }","typeGuard":"boolean isAddableToResult( org.apache.commons.vfs2.FileObject f ) { return f != null && f.exists(); }","tryCatchPattern":"try { addFilenameToResult(); } catch ( KettleException e ) { logError( \"Result-file registration failed: \" + e.getCause(), e ); }","preventionTips":["Always inspect getCause() — this wrapper hides the real failure.","Keep the output path on stable, local storage during execution.","Test the transformation end-to-end after renaming steps or transformations."],"tags":["pentaho-kettle","excel-output","result-files","wrapped-exception"],"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"}