Programmer-RD-AI commented on code in PR #56217:
URL: https://github.com/apache/airflow/pull/56217#discussion_r2392148123


##########
providers/sftp/src/airflow/providers/sftp/operators/sftp.py:
##########
@@ -206,10 +206,18 @@ def execute(self, context: Any) -> str | list[str] | None:
                 for _remote_filepath in remote_filepath_array:
                     file_msg = f"{_remote_filepath}"
                     self.log.info("Starting to delete %s", file_msg)
-                    if self.sftp_hook.isdir(_remote_filepath):
-                        self.sftp_hook.delete_directory(_remote_filepath, 
include_files=True)
-                    else:
-                        self.sftp_hook.delete_file(_remote_filepath)
+                    try:
+                        if self.sftp_hook.isdir(_remote_filepath):
+                            self.sftp_hook.delete_directory(_remote_filepath, 
include_files=True)
+                        else:
+                            self.sftp_hook.delete_file(_remote_filepath)
+                    except OSError as e:
+                        if "no such file" in str(e).lower():

Review Comment:
   i think checking based on the text of the error is a bad idea here, isn't 
the OSError being raised enough to know that it was due to the file or 
directory not being found in the path? or if there is a specific error you can 
expect then that would work as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to