Skip to content

Commit

Permalink
Fix NullPointerExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Ernst authored and jernst committed Oct 19, 2024
1 parent 2811f6a commit 44258b0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/feditest/nodedrivers/mastodon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def actor_has_received_object(self, object_uri: str) -> dict[str, Any]:
response = find_first_in_array(elements, lambda s: s['uri'] == object_uri)
if not response:
# Home timeline second case: an announce/boost was created by an account we follow -- need to look for the original URI
if reblog_response := find_first_in_array(elements, lambda s: 'reblog' in s and s['reblog']['uri'] == object_uri) :
if reblog_response := find_first_in_array(elements, lambda s: 'reblog' in s and s['reblog'] and 'uri' in s['reblog'] and s['reblog']['uri'] == object_uri) :
response = reblog_response['reblog']
if not response:
# Check for it in notifications: mentions arrive here
Expand Down Expand Up @@ -458,7 +458,7 @@ def _find_account_dict_by_other_actor_acct_uri(self, other_actor_acct_uri: str)
raise ValueError(f'Unexpected type: { ret }')


def _find_note_dict_by_uri(self, uri: str) -> dict[str,Any]:
def _find_note_dict_by_uri(self, uri: str) -> dict[str,Any] | None:
"""
Find a the dict for a status, or None.
"""
Expand All @@ -470,6 +470,8 @@ def _find_note_dict_by_uri(self, uri: str) -> dict[str,Any]:
results = self.http_get('/api/v2/search?' + urlencode(args))

ret = find_first_in_array(results.get('statuses'), lambda b: b['uri'] == uri)
if ret is None:
return None
if isinstance(ret, dict):
return cast(dict[str,Any], ret)
raise ValueError(f'Unexpected type: { ret }')
Expand Down

0 comments on commit 44258b0

Please sign in to comment.