File tree Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Expand file tree Collapse file tree 3 files changed +31
-10
lines changed Original file line number Diff line number Diff line change 1010
1111from aleph .services .ipfs .common import make_ipfs_client
1212from aleph .services .utils import get_IP
13- from aleph .types .message_status import FileUnavailable
13+ from aleph .types .message_status import FileContentUnavailable , FileUnavailable
1414from aleph .utils import run_in_executor
1515
1616LOGGER = logging .getLogger (__name__ )
@@ -113,8 +113,9 @@ async def get_ipfs_size(
113113 await asyncio .sleep (0.5 )
114114 continue
115115 except asyncio .TimeoutError :
116- result = None
117- await asyncio .sleep (0.5 )
116+ raise FileContentUnavailable (
117+ "Could not retrieve IPFS content at this time"
118+ )
118119 except (
119120 concurrent .futures .CancelledError ,
120121 aiohttp .client_exceptions .ClientConnectorError ,
Original file line number Diff line number Diff line change @@ -169,6 +169,16 @@ def __init__(self, file_hash: str):
169169 super ().__init__ (f"File not found: { file_hash } " )
170170
171171
172+ class FileContentNotFoundException (RetryMessageException ):
173+ """
174+ A file required to process the message could not be found, locally and/or
175+ on the network.
176+ """
177+
178+ def __init__ (self , file_hash : str ):
179+ super ().__init__ (f"File content not found: { file_hash } " )
180+
181+
172182class MessageContentUnavailable (FileNotFoundException ):
173183 """
174184 The message content is not available at the moment (storage/IPFS item types).
@@ -185,6 +195,14 @@ class FileUnavailable(FileNotFoundException):
185195 error_code = ErrorCode .FILE_UNAVAILABLE
186196
187197
198+ class FileContentUnavailable (FileContentNotFoundException ):
199+ """
200+ A file pointed to by the message is not available at the moment.
201+ """
202+
203+ error_code = ErrorCode .FILE_UNAVAILABLE
204+
205+
188206class NoAmendTarget (InvalidMessageException ):
189207 """
190208 A POST with type = amend does not specify a value in the ref field.
Original file line number Diff line number Diff line change 55import pytest
66
77from aleph .services .ipfs .service import IpfsService
8+ from aleph .types .message_status import FileContentUnavailable
89
910
1011@pytest .mark .asyncio
@@ -178,14 +179,15 @@ async def test_get_ipfs_size_timeout_error():
178179
179180 service = IpfsService (ipfs_client = ipfs_client )
180181
181- # Mock asyncio.sleep to not actually sleep during test
182- with patch ("asyncio.sleep" , new_callable = AsyncMock ):
183- # Execute
184- result = await service .get_ipfs_size ("test_hash" )
182+ with pytest .raises (FileContentUnavailable ):
183+ # Mock asyncio.sleep to not actually sleep during test
184+ with patch ("asyncio.sleep" , new_callable = AsyncMock ):
185+ # Execute
186+ result = await service .get_ipfs_size ("test_hash" )
185187
186- # Assert
187- assert result is None
188- ipfs_client .dag .get .assert_called_once_with ("test_hash" )
188+ # Assert
189+ assert result is None
190+ ipfs_client .dag .get .assert_called_once_with ("test_hash" )
189191
190192
191193@pytest .mark .asyncio
You can’t perform that action at this time.
0 commit comments