Skip to content

Commit

Permalink
add error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-zora committed Sep 21, 2023
1 parent 1d3a4dd commit bde4713
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 22 deletions.
14 changes: 10 additions & 4 deletions offchain/metadata/parsers/catchall/default_catchall.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from typing import Optional

from offchain.logger.logging import logger
from offchain.metadata.models.metadata import Attribute, MediaDetails, Metadata
from offchain.metadata.models.token import Token
from offchain.metadata.parsers.catchall.catchall_parser import CatchallParser
Expand Down Expand Up @@ -100,8 +101,10 @@ async def gen_image_details(self, raw_data: dict) -> Optional[MediaDetails]: #
)
details.size = size
details.mime_type = content_type
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image {image_uri=}. {str(e)}"
)

if isinstance(raw_data.get("image_details"), dict):
details.size = raw_data["image_details"].get("size")
Expand Down Expand Up @@ -142,8 +145,11 @@ async def gen_content_details(self, raw_data: dict) -> Optional[MediaDetails]:
)
details.size = size
details.mime_type = content_type
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch mime_type_and_size "
f"{content_uri=}. {str(e)}"
)
if isinstance(raw_data.get("animation_details"), dict):
details.size = raw_data["animation_details"].get("size")
details.sha256 = raw_data["animation_details"].get("sha256")
Expand Down
7 changes: 5 additions & 2 deletions offchain/metadata/parsers/collection/artblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.models.metadata import (
Attribute,
MediaDetails,
Expand Down Expand Up @@ -260,8 +261,10 @@ async def gen_image(self, raw_data: dict) -> Optional[MediaDetails]: # type: ig
image.mime_type = content_type
image.size = size
return image
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image {image_uri=}. {str(e)}"
)

async def _gen_parse_metadata_impl(
self, token: Token, raw_data: dict, *args, **kwargs
Expand Down
7 changes: 5 additions & 2 deletions offchain/metadata/parsers/collection/autoglyphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.constants.autoglyphs import get_symbol_by_index
from offchain.metadata.models.metadata import (
Attribute,
Expand Down Expand Up @@ -107,8 +108,10 @@ async def gen_image_details(self, raw_data: dict) -> Optional[MediaDetails]: #
content_type, size = await self.fetcher.gen_fetch_mime_type_and_size(image_uri) # type: ignore[arg-type] # noqa: E501
details.mime_type = content_type
details.size = size
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image details {image_uri=}. {str(e)}"
)
return details

def get_content_details(self, index: int) -> Optional[MediaDetails]:
Expand Down
12 changes: 8 additions & 4 deletions offchain/metadata/parsers/collection/ens.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ async def gen_image(self, raw_data: dict) -> Optional[MediaDetails]: # type: ig
image.mime_type = content_type
image.size = size
return image
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image {image_uri=}. {str(e)}"
)

async def gen_background_image(self, raw_data: dict) -> Optional[MediaDetails]: # type: ignore[return, type-arg] # noqa: E501
bg_image_uri = raw_data.get("background_image")
Expand All @@ -147,8 +149,10 @@ async def gen_background_image(self, raw_data: dict) -> Optional[MediaDetails]:
image.mime_type = content_type
image.size = size
return image
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch background image {bg_image_uri=}. {str(e)}"
)

async def _gen_parse_metadata_impl(self, token: Token, raw_data: dict, *args, **kwargs) -> Optional[Metadata]: # type: ignore[no-untyped-def, type-arg] # noqa: E501
ens_chain_name = self.make_ens_chain_name(token.chain_identifier)
Expand Down
7 changes: 5 additions & 2 deletions offchain/metadata/parsers/collection/hashmasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.models.metadata import (
Attribute,
MediaDetails,
Expand Down Expand Up @@ -97,8 +98,10 @@ async def gen_image(self, raw_data: dict) -> Optional[MediaDetails]: # type: ig
image.mime_type = content_type
image.size = size
return image
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image {image_uri=}. {str(e)}"
)

def parse_metadata(self, token: Token, raw_data: dict, *args, **kwargs) -> Optional[Metadata]: # type: ignore[no-untyped-def, type-arg] # noqa: E501
token.uri = f"https://hashmap.azurewebsites.net/getMask/{token.token_id}"
Expand Down
7 changes: 5 additions & 2 deletions offchain/metadata/parsers/collection/makersplace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.adapters.ipfs import build_request_url
from offchain.metadata.models.metadata import MediaDetails, Metadata
from offchain.metadata.models.token import Token
Expand Down Expand Up @@ -86,8 +87,10 @@ async def gen_content_details(self, raw_data: dict) -> Optional[MediaDetails]:
content_type, size = await self.fetcher.gen_fetch_mime_type_and_size(url)
details.mime_type = content_type
details.size = size
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch content detail {url=}. {str(e)}"
)

return details

Expand Down
14 changes: 10 additions & 4 deletions offchain/metadata/parsers/collection/superrare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.models.metadata import (
MediaDetails,
Metadata,
Expand Down Expand Up @@ -41,8 +42,10 @@ async def gen_image_details(self, raw_data: dict) -> Optional[MediaDetails]: #
)
details.mime_type = content_type
details.size = size
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch image {image_uri=}. {str(e)}"
)
return details

def get_content_details(self, raw_data: dict) -> Optional[MediaDetails]: # type: ignore[type-arg] # noqa: E501
Expand Down Expand Up @@ -88,8 +91,11 @@ async def gen_content_details(self, raw_data: dict) -> Optional[MediaDetails]:
)
details.mime_type = content_type
details.size = size
except Exception:
pass
except Exception as e:
logger.error(
f"{self.__class__.__name__} fail to fetch content type and size "
f"{content_uri=}. {str(e)}"
)

return details

Expand Down
5 changes: 3 additions & 2 deletions offchain/metadata/parsers/collection/zora.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from offchain.constants.addresses import CollectionAddress
from offchain.logger.logging import logger
from offchain.metadata.models.metadata import (
MediaDetails,
Metadata,
Expand Down Expand Up @@ -99,8 +100,8 @@ async def gen_content_details(self, uri: str) -> Optional[MediaDetails]:
try:
content_type, size = await self.fetcher.gen_fetch_mime_type_and_size(uri)
return MediaDetails(uri=uri, size=size, sha256=None, mime_type=content_type)
except Exception:
pass
except Exception as e:
logger.error(f"{self.__class__.__name__} fail to content {uri=}. {str(e)}")

return None

Expand Down

0 comments on commit bde4713

Please sign in to comment.