Skip to content

Commit

Permalink
Fix: Solve test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor committed Sep 25, 2024
1 parent 55162cb commit 5168a0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/aleph/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Basically manages the IPFS storage.
"""
import asyncio
import json
import logging
from hashlib import sha256
from typing import Any, IO, Optional, cast, Final
Expand Down Expand Up @@ -83,6 +84,10 @@ async def get_message_content(self, message: PendingMessageDb) -> MessageContent
error_msg = f"Can't decode JSON: {e}"
LOGGER.warning(error_msg)
raise InvalidContent(error_msg)
except json.decoder.JSONDecodeError as e:
error_msg = f"Can't decode JSON: {e}"
LOGGER.warning(error_msg)
raise InvalidContent(error_msg)

return MessageContent(
hash=item_hash,
Expand Down
4 changes: 2 additions & 2 deletions src/aleph/toolkit/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def load(fp: IO) -> Any:
def loads(s: Union[bytes, str]) -> Any:
try:
return orjson.loads(s)
except:
except TypeError as e:
return json.loads(s)


Expand All @@ -39,5 +39,5 @@ def dump(fp: IO, obj: Any) -> None:
def dumps(obj: Any) -> bytes:
try:
return orjson.dumps(obj)
except:
except TypeError as e:
return json.dumps(obj).encode()
2 changes: 1 addition & 1 deletion tests/toolkit/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_reject_nans():
"""

serialized_json = '{"1": 1, "2": 2, "3": NaN}'
with pytest.raises(aleph_json.DecodeError):
with pytest.raises(json.decoder.JSONDecodeError):
_ = aleph_json.loads(serialized_json)


Expand Down

0 comments on commit 5168a0b

Please sign in to comment.