From d86bb38bf9a0ced8029f8a4b895e1a6be1ccb339 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Tue, 4 Jun 2024 11:09:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20`SshTransport`:=20Return=20`File?= =?UTF-8?q?NotFoundError`=20if=20destination=20parent=20does=20not=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 101a8d61ba1c9f50a0231cd249c5a7f7ff1d77a4 the engine was adapted to simply log a warning in case a `FileNotFoundError` was raised by a remove copy operation. The logic is that in case the source file does not exist this operation will fail every time. Hence, it is not useful to trigger the exponential backoff mechanism and have this operation fail multiple times. However, when the parent folder of the target doesn't exist the remote copy command will fail as well. In this case, the returned error was still an `OSError`, which is not caught by the engine and logged as a warning. To obtain similar behaviour for these two failures, we now parse the `stderr` returned by the `exec_command_wait_bytes` method. In case it refers to a file or directory not being found, we raise a `FileNoteFoundError` instead of a generic `OSError`. Since this also deals with the case of a missing remote source file, we remove the check in the `SshTransport.copy()` method. --- src/aiida/transports/plugins/ssh.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index b15850d75c..773c1f51fc 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1167,9 +1167,6 @@ def copy(self, remotesource, remotedestination, dereference=False, recursive=Tru self._exec_cp(cp_exe, cp_flags, file, remotedestination) else: - if not self.path_exists(remotesource): - raise FileNotFoundError('Source not found') - self._exec_cp(cp_exe, cp_flags, remotesource, remotedestination) def _exec_cp(self, cp_exe, cp_flags, src, dst): @@ -1188,6 +1185,9 @@ def _exec_cp(self, cp_exe, cp_flags, src, dst): retval, stdout, stderr, command ) ) + if 'No such file or directory' in str(stderr): + raise FileNotFoundError(f'Error while executing cp: {stderr}') + raise OSError( 'Error while executing cp. Exit code: {}, ' "stdout: '{}', stderr: '{}', " "command: '{}'".format( retval, stdout, stderr, command