From 47ce3a0a8c7ba5ca1531c6d117c70289389610dd Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 29 Aug 2024 17:25:41 -0400 Subject: [PATCH] Allow to communicate ErrorMsg for CHECKURL-FAILURE via RemoteError exception Similar pattern already used in various other locations but not for this check. I used .rstrip() to guarantee no dangling whitespaces (which would break the existing test). https://git-annex.branchable.com/design/external_special_remote_protocol/ says that CHECKURL-FAILURE ErrorMsg Indicates that the requested url could not be accessed. so ErrorMsg is entirely legit. --- annexremote/annexremote.py | 4 ++-- tests/test_GitAnnexRequestMessages.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/annexremote/annexremote.py b/annexremote/annexremote.py index e3013d8..524e047 100644 --- a/annexremote/annexremote.py +++ b/annexremote/annexremote.py @@ -675,8 +675,8 @@ def do_CLAIMURL(self, url): def do_CHECKURL(self, url): try: reply = self.remote.checkurl(url) - except RemoteError: - return "CHECKURL-FAILURE" + except RemoteError as e: + return "CHECKURL-FAILURE {e}".format(e=e).rstrip() if not reply: return "CHECKURL-FAILURE" elif reply is True: diff --git a/tests/test_GitAnnexRequestMessages.py b/tests/test_GitAnnexRequestMessages.py index cce8902..5165a50 100644 --- a/tests/test_GitAnnexRequestMessages.py +++ b/tests/test_GitAnnexRequestMessages.py @@ -319,6 +319,14 @@ def test_CheckurlFailure(self): self.remote.checkurl.assert_called_once_with("Url") self.assertEqual(utils.second_buffer_line(self.output), "CHECKURL-FAILURE") + def test_CheckurlFailureErrorMsg(self): + self.remote.checkurl.side_effect = RemoteError("ErrorMsg") + self.annex.Listen(io.StringIO("CHECKURL Url")) + self.remote.checkurl.assert_called_once_with("Url") + self.assertEqual( + utils.second_buffer_line(self.output), "CHECKURL-FAILURE ErrorMsg" + ) + def test_CheckurlFailureByException(self): self.remote.checkurl.return_value = False self.annex.Listen(io.StringIO("CHECKURL Url"))