Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate token uri in logging #99

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions offchain/metadata/pipelines/metadata_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
)


def _truncate_uri(uri: str, max_length: int = 100) -> str:
if len(uri) <= max_length:
return uri

keep_length = (max_length - 3) // 2 # 3 is for the '...'

return uri[:keep_length] + "..." + uri[-keep_length:]


class MetadataPipeline(BasePipeline):
"""Pipeline for processing NFT metadata.

Expand Down Expand Up @@ -161,7 +170,7 @@ def fetch_token_metadata(
try:
raw_data = self.fetcher.fetch_content(token.uri)
except Exception as e:
error_message = f"({token.chain_identifier}-{token.collection_address}-{token.token_id}) Failed to parse token uri: {token.uri}. {str(e)}" # noqa: E501
error_message = f"({token.chain_identifier}-{token.collection_address}-{token.token_id}) Failed to parse token uri: {_truncate_uri(token.uri)}. {str(e)}" # noqa: E501
logger.error(error_message)
possible_metadatas_or_errors.append(
MetadataProcessingError.from_token_and_error(
Expand Down Expand Up @@ -216,9 +225,9 @@ async def gen_fetch_token_metadata(
Union[Metadata, MetadataProcessingError]: returns either a Metadata
or a MetadataProcessingError if unable to parse.
"""
possible_metadatas_or_errors: list[
Union[Metadata, MetadataProcessingError]
] = []
possible_metadatas_or_errors: list[Union[Metadata, MetadataProcessingError]] = (
[]
)

if not token.uri:
return MetadataProcessingError.from_token_and_error(
Expand All @@ -230,7 +239,7 @@ async def gen_fetch_token_metadata(
try:
raw_data = await self.fetcher.gen_fetch_content(token.uri)
except Exception as e:
error_message = f"({token.chain_identifier}-{token.collection_address}-{token.token_id}) Failed to parse token uri: {token.uri}. {str(e)}" # noqa: E501
error_message = f"({token.chain_identifier}-{token.collection_address}-{token.token_id}) Failed to parse token uri: {_truncate_uri(token.uri)}. {str(e)}" # noqa: E501
logger.error(error_message)
possible_metadatas_or_errors.append(
MetadataProcessingError.from_token_and_error(
Expand Down
Loading