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

Return error instead of just logging it if client fails #1632

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

zkokelj
Copy link
Contributor

@zkokelj zkokelj commented Nov 1, 2023

Why this change is needed

Please provide a description and a link to the underlying ticket

What changes were made as part of this PR

Please provide a high level list of the changes made

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link

coderabbitai bot commented Nov 1, 2023

Walkthrough

The changes primarily focus on enhancing error handling in the AccountManager and WalletExtension structs. The ProxyRequest function in AccountManager and the AddAddressToUser function in WalletExtension now return errors when they encounter issues, allowing for better error management by the calling functions.

Changes

File Path Summary
.../accountmanager/account_manager.go Added a return statement in the ProxyRequest function. This allows the function to return an error if there is an issue subscribing to multiple clients.
.../wallet_extension.go Updated the AddAddressToUser function to return an error if there is an issue creating an encrypted client. This change allows the caller to handle the error appropriately.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@zkokelj zkokelj requested a review from otherview November 1, 2023 10:23
@zkokelj zkokelj marked this pull request as ready for review November 1, 2023 10:24
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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fb4c449 and eb4cbb9.
Files selected for processing (2)
  • tools/walletextension/accountmanager/account_manager.go (1 hunks)
  • tools/walletextension/wallet_extension.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/accountmanager/account_manager.go

Comment on lines 249 to 253
encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature, w.Logger())
if err != nil {
w.Logger().Error(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
return errors.New(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
}
Copy link

Choose a reason for hiding this comment

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

The error message is being wrapped twice, which is unnecessary. The error returned from common.CreateEncClient should be returned directly after logging it.

- w.Logger().Error(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
- return errors.New(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
+ w.Logger().Error(fmt.Sprintf("error creating encrypted client for user: (%s), %v", hexUserID, err))
+ return err

Commitable suggestion (Beta)
Suggested change
encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature, w.Logger())
if err != nil {
w.Logger().Error(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
return errors.New(fmt.Errorf("error creating encrypted client for user: (%s), %w", hexUserID, err).Error())
}
encClient, err := common.CreateEncClient(w.hostAddr, addressFromMessage.Bytes(), privateKeyBytes, signature, w.Logger())
if err != nil {
w.Logger().Error(fmt.Sprintf("error creating encrypted client for user: (%s), %v", hexUserID, err))
return err
}

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between eb4cbb9 and ba2aa03.
Files selected for processing (2)
  • tools/walletextension/accountmanager/account_manager.go (1 hunks)
  • tools/walletextension/wallet_extension.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • tools/walletextension/accountmanager/account_manager.go
Additional comments: 1
tools/walletextension/wallet_extension.go (1)
  • 249-255: The error handling and logging are correctly implemented. The function now returns an error if there's an issue creating an encrypted client, allowing the caller to handle the error appropriately. This is a good practice for error management and system reliability.

@zkokelj zkokelj merged commit aae2f5f into main Nov 1, 2023
2 checks passed
@zkokelj zkokelj deleted the ziga/og_return_error_if_client_fails branch November 1, 2023 10:27
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.

2 participants