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

fix(torii): avoid panic on fetch token URI fail #2750

Merged
merged 1 commit into from
Dec 2, 2024
Merged

Conversation

glihm
Copy link
Collaborator

@glihm glihm commented Dec 2, 2024

In some occasions, the token URI may not be fetched correctly. Since it's mostly use for metadata, a default metadata is used in this scenario.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for fetching token URIs, allowing the process to continue even if the token URI retrieval fails.
    • Enhanced logging to provide contextual information when errors occur, improving transparency for users.
  • Improvements

    • Adjusted logic to handle empty token URIs more gracefully, ensuring a smoother user experience when metadata is not available.

In this occasions, the token URI may not be fetched correctly.
Since it's mostly use for metadata, a default metadata is
used in this scenario.
Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

Ohayo, sensei! The recent changes in the erc.rs file focus on enhancing error handling and logging within the process_register_erc721_token_query method. Key modifications include the introduction of a warning log for failed token URI fetch attempts, allowing the function to continue with an empty string instead of terminating with an error. The logic for handling the token URI has been refined to check its validity before fetching metadata, improving code maintainability and robustness.

Changes

File Path Change Summary
crates/torii/core/src/executor/erc.rs Enhanced error handling and logging in process_register_erc721_token_query. Added warn log for token URI fetch failures, allowing function to proceed with an empty string for token URI. Adjusted logic to check if token URI is empty before fetching metadata.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ERC
    participant MetadataService

    User->>ERC: Register ERC721 Token
    ERC->>ERC: Process Register Token
    ERC->>ERC: Fetch Token URI
    alt Token URI Fetch Success
        ERC->>MetadataService: Fetch Metadata
    else Token URI Fetch Failure
        ERC->>ERC: Log Warning
        ERC->>ERC: Assign Empty String to Metadata
    end
    ERC->>User: Return Metadata
Loading

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
crates/torii/core/src/executor/erc.rs (2)

179-186: LGTM! Robust error handling with informative logging.

The warning log provides excellent context with both contract address and token ID. The approach to continue with empty metadata aligns perfectly with the PR's objective to avoid panics.

A tiny suggestion to make the warning message even more helpful:

-                "Error fetching token URI, empty metadata will be used instead.",
+                "Failed to fetch token URI (tried both token_uri and tokenURI), falling back to empty metadata.",

202-213: Consider adding debug logging for metadata fetch outcomes.

Ohayo sensei! The metadata handling logic is robust, but we could improve observability:

         let metadata = if token_uri.is_empty() {
+            debug!("Using empty metadata for empty token URI");
             "".to_string()
         } else {
             let metadata = Self::fetch_metadata(&token_uri).await.with_context(|| {
                 format!(
                     "Failed to fetch metadata for token_id: {}",
                     register_erc721_token.actual_token_id
                 )
             })?;
+            debug!(
+                token_id = %register_erc721_token.actual_token_id,
+                "Successfully fetched and parsed metadata"
+            );
 
             serde_json::to_string(&metadata).context("Failed to serialize metadata")?
         };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a0a173e and c148789.

📒 Files selected for processing (1)
  • crates/torii/core/src/executor/erc.rs (3 hunks)
🔇 Additional comments (1)
crates/torii/core/src/executor/erc.rs (1)

13-13: LGTM! Import addition aligns with new logging.

Ohayo! The addition of warn to the tracing imports is well-placed and necessary for the new error handling approach.

@glihm
Copy link
Collaborator Author

glihm commented Dec 2, 2024

will wait feedback from @ponderingdemocritus on preview--c148789 before going ahead and merge.

Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Project coverage is 56.10%. Comparing base (a0a173e) to head (c148789).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/torii/core/src/executor/erc.rs 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2750      +/-   ##
==========================================
- Coverage   56.10%   56.10%   -0.01%     
==========================================
  Files         427      427              
  Lines       54516    54522       +6     
==========================================
+ Hits        30586    30587       +1     
- Misses      23930    23935       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm merged commit 6644564 into main Dec 2, 2024
18 of 31 checks passed
@glihm glihm deleted the fix/torii-token-uri branch December 2, 2024 23:35
augustin-v pushed a commit to augustin-v/dojo that referenced this pull request Dec 4, 2024
fix: ensure torii doesn't stop on fetch URI fail

In this occasions, the token URI may not be fetched correctly.
Since it's mostly use for metadata, a default metadata is
used in this scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant