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

refactor: add close body after use and fix lint #22248

Merged
merged 5 commits into from
Oct 14, 2024

Conversation

hoank101
Copy link
Contributor

@hoank101 hoank101 commented Oct 14, 2024

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Enhanced encoding and decoding capabilities for Quad instances, including support for non-terminal keys.
    • Improved schema representation for Quads.
  • Bug Fixes

    • Updated error handling in the indexer for better error message formatting.
    • Added resource management for closing response bodies in the chain registry.
  • Refactor

    • Simplified initialization of the getProtoRegistry field in the Consensus struct.
    • Removed unnecessary JSON sorting function from tests.

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request enhance the functionality of the quadKeyCodec struct in collections/quad.go by adding methods for encoding and decoding Quad instances, including handling non-terminal keys. Modifications in schema/indexer/start.go improve error handling. The getProtoRegistry field in server/v2/cometbft/abci.go is simplified. In tests/integration/tx/aminojson/aminojson_test.go, the sortJson function is removed, and tools/hubl/internal/registry.go adds error handling for resource management.

Changes

File Change Summary
collections/quad.go Added methods: Encode, Decode, EncodeNonTerminal, DecodeNonTerminal, Size, SizeNonTerminal. Modified SchemaCodec.
schema/indexer/start.go Updated error message formatting in StartIndexing to use %w for better error unwrapping.
server/v2/cometbft/abci.go Simplified initialization of getProtoRegistry in the Consensus struct.
tests/integration/tx/aminojson/aminojson_test.go Removed sortJson function.
tools/hubl/internal/registry.go Added error handling for closing the response body in GetChainRegistryEntry.

Possibly related PRs

Suggested reviewers

  • facundomedica
  • testinginprod
  • julienrbrt
  • aaronc
  • kocubinski

📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 89506df and 8df8a64.

📒 Files selected for processing (1)
  • server/v2/cometbft/abci.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/v2/cometbft/abci.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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
Contributor

@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: 1

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 65ed5eb and 89506df.

📒 Files selected for processing (5)
  • collections/quad.go (0 hunks)
  • schema/indexer/start.go (1 hunks)
  • server/v2/cometbft/abci.go (1 hunks)
  • tests/integration/tx/aminojson/aminojson_test.go (0 hunks)
  • tools/hubl/internal/registry.go (1 hunks)
💤 Files with no reviewable changes (2)
  • collections/quad.go
  • tests/integration/tx/aminojson/aminojson_test.go
✅ Files skipped from review due to trivial changes (1)
  • server/v2/cometbft/abci.go
🧰 Additional context used
📓 Path-based instructions (2)
schema/indexer/start.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

tools/hubl/internal/registry.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (1)
tools/hubl/internal/registry.go (1)

34-37: Excellent addition of error handling for response body closure.

The new code properly handles potential errors when closing the response body, which is a good practice for resource management. This change aligns well with Go's error handling conventions and helps prevent resource leaks.

@@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) {

targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType)
if err != nil {
return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err)
return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Ensure consistent error wrapping by using %w in all fmt.Errorf calls

The following fmt.Errorf instances in schema/indexer/start.go do not use the %w verb and should be updated to enhance error handling consistency:

  • return IndexingTarget{}, fmt.Errorf("indexer type %q not found", targetCfg.Type)
  • return IndexingTarget{}, fmt.Errorf("indexer filter options are not supported yet")
  • return nil, fmt.Errorf("can't convert %T to %T", cfg, IndexingConfig{})

Recommended Action:

Update these instances to utilize the %w verb for error wrapping, ensuring that the original error is preserved and can be unwrapped later. For example:

return IndexingTarget{}, fmt.Errorf("indexer type %q not found: %w", targetCfg.Type, err)

This change aligns with Go's error handling best practices and improves the ability to trace error chains.

🔗 Analysis chain

Improved error wrapping using %w verb

The change from %v to %w in the error formatting is a good improvement. This modification allows for better error handling and debugging capabilities.

Reasons for approval:

  1. Using %w verb wraps the original error, preserving the error chain.
  2. This change aligns with Go 1.13+ error wrapping best practices.
  3. It follows the Uber Go Style Guide recommendation for error wrapping.

Suggestion for further improvement:
Consider updating other error handling instances in this file to use %w where appropriate, for consistency. This would involve checking other fmt.Errorf calls within the StartIndexing function and potentially other functions in this file.

To ensure consistency across the file, let's check for other instances of error formatting:

This will help identify if there are other error formatting calls that might benefit from using %w.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other fmt.Errorf calls in the file
rg --type go 'fmt\.Errorf\(' schema/indexer/start.go

Length of output: 411

schema/indexer/start.go Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the C:schema label Oct 14, 2024
@hoank101 hoank101 requested a review from julienrbrt October 14, 2024 07:18
@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 14, 2024
@julienrbrt julienrbrt added this pull request to the merge queue Oct 14, 2024
Merged via the queue into cosmos:main with commit 4274dcf Oct 14, 2024
70 of 72 checks passed
mergify bot pushed a commit that referenced this pull request Oct 14, 2024
(cherry picked from commit 4274dcf)

# Conflicts:
#	collections/quad.go
#	tools/hubl/internal/registry.go
julienrbrt added a commit that referenced this pull request Oct 15, 2024
#22260)

Co-authored-by: Hoa Nguyen <hoa@notional.ventures>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:collections C:Hubl Tool: Hubl C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants