{"record":{"id":"6f2454655d526ca4","repo":"pentaho/pentaho-kettle","slug":"error-0001-target-exists","errorCode":"ERROR_0001_TARGET_EXISTS","errorMessage":"ReportExportTask.ERROR_0001_TARGET_EXISTS","messagePattern":"ReportExportTask\\.ERROR_0001_TARGET_EXISTS","errorType":"error_code","errorClass":"ReportProcessingException","httpStatus":null,"severity":"error","filePath":"plugins/pentaho-reporting/impl/src/main/java/org/pentaho/di/trans/steps/pentahoreporting/ReportExportTask.java","lineNumber":76,"sourceCode":"\n    this.targetPath = targetPath;\n    this.createParentFolder = createParentFolder;\n  }\n\n  /**\n   * When an object implementing interface <code>Runnable</code> is used to create a thread, starting the thread causes\n   * the object's <code>run</code> method to be called in that separately executing thread.\n   * <p/>\n   * The general contract of the method <code>run</code> is that it may take any action whatsoever.\n   *\n   * @see Thread#run()\n   */\n  public void run() {\n    try {\n      targetFile = KettleVFS.getInstance( bowl ).getFileObject( targetPath );\n      if ( targetFile.exists() ) {\n        if ( !targetFile.delete() ) {\n          throw new ReportProcessingException( BaseMessages.getString( PKG, \"ReportExportTask.ERROR_0001_TARGET_EXISTS\" ) );\n        }\n      }\n\n      if ( createParentFolder ) {\n        targetFile.getParent().createFolder();\n      } else if ( !targetFile.getParent().exists() ) {\n        throw new ReportProcessingException( BaseMessages.getString( PKG,\n          \"ReportExportTask.PARENT_FOLDER_DOES_NOT_EXIST\", targetFile.getParent().getName().getPath() ) );\n      }\n\n      execute();\n    } catch ( Exception ex ) {\n      statusListener.setStatus( StatusType.ERROR, BaseMessages.getString( PKG,  \"ReportExportTask.USER_EXPORT_FAILED\" ), ex );\n      logger.error( BaseMessages.getString( PKG, \"ReportExportTask.ERROR.GenerationFailed\", targetPath ) );\n    }\n  }\n\n  protected void execute() throws Exception {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/pentaho-reporting/impl/src/main/java/org/pentaho/di/trans/steps/pentahoreporting/ReportExportTask.java#L58-L94","documentation":"ReportExportTask.run() resolves the target file via KettleVFS and, if it already exists, attempts to delete it before rendering. If the delete fails, it throws ReportProcessingException with ReportExportTask.ERROR_0001_TARGET_EXISTS. The task cannot start writing the report while an unremovable file occupies the target path.","triggerScenarios":"targetFile.exists() is true and targetFile.delete() returns false — typically because the OS refuses the delete.","commonSituations":"Target PDF/Excel file is open in a viewer or editor holding a lock (common on Windows); file owned by another user without delete permission; target path is actually a non-empty directory; VFS provider cannot delete (e.g. remote filesystem restrictions).","solutions":["Close any application holding the target file open, then rerun the transformation","Delete the target file manually and confirm the account running Kettle has delete permission on the directory","Choose a different target filename/path in the step settings","If targeting a remote VFS location, verify the provider supports delete and credentials allow it"],"exampleFix":"// before\nif ( !targetFile.delete() ) {\n  throw new ReportProcessingException( BaseMessages.getString( PKG, \"ReportExportTask.ERROR_0001_TARGET_EXISTS\" ) );\n}\n// after\nif ( !targetFile.delete() ) {\n  throw new ReportProcessingException( BaseMessages.getString( PKG,\n    \"ReportExportTask.ERROR_0001_TARGET_EXISTS\" ) + \" (\" + targetPath + \")\" );\n}","handlingStrategy":"validation","validationCode":"FileObject target = KettleVFS.getInstance( bowl ).getFileObject( targetPath );\nif ( target.exists() && !target.delete() ) {\n  throw new KettleException( \"Target exists and cannot be deleted: \" + targetPath );\n}","typeGuard":null,"tryCatchPattern":"try {\n  exportTask.run();\n} catch ( ReportProcessingException e ) {\n  if ( e.getMessage().contains( \"ERROR_0001\" ) ) {\n    logError( \"Target file locked: \" + targetPath );\n  }\n}","preventionTips":["Close viewers/editors holding the output file before runs","Delete or rotate old output files in a prior transformation step","Give the Kettle service account delete rights on the output directory","Use unique timestamped filenames to avoid collisions"],"tags":["vfs","file-io","windows-lock"],"backgroundTag":"file-already-exists","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"}