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 keystore creation bug #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

cbrit
Copy link
Member

@cbrit cbrit commented Jul 22, 2024

Closes #251

Summary by CodeRabbit

  • New Features

    • Enhanced error handling for commands related to Cosmos and Ethereum key management, providing clearer feedback for failed operations.
  • Bug Fixes

    • Improved robustness of key and wallet loading processes by adding explicit error handling, preventing potential runtime failures.
  • Documentation

    • Updated method return types across configuration handling to allow for better error propagation and management.
  • Chores

    • Refined the code structure for clarity and maintainability, emphasizing a shift to idiomatic error handling practices.

@cbrit cbrit requested a review from zmanian July 22, 2024 16:41
Copy link

coderabbitai bot commented Jul 22, 2024

Walkthrough

The recent changes primarily focus on enhancing error handling across various command implementations in the codebase. This includes replacing methods that silently fail with those that provide explicit error messages, improving robustness by ensuring that operations fail gracefully when encountering issues like missing keystores or load failures. The modifications also shift some functionalities to require pre-existing resources, significantly refining the user experience and minimizing potential runtime errors.

Changes

Files Group Change Summary
src/commands/* (e.g., cosmos_to_eth.rs, erc20.rs, eth_to_cosmos.rs) Error handling was improved by adding .expect calls to key loading functions, ensuring clear panic messages on failure.
src/commands/keys/cosmos/* (e.g., add.rs, delete.rs, recover.rs, etc.) The method for accessing the keystore was changed from create_or_open to open, eliminating the creation option and enforcing existing keystore checks.
src/commands/keys/eth/* (e.g., add.rs, delete.rs, import.rs, etc.) Similar to cosmos commands, the create_or_open method was replaced with open, emphasizing the need for an existing keystore.
src/config.rs Enhanced error handling in the StewardConfig struct by modifying methods to return Result types, allowing better error propagation and clearer failure contexts.

Assessment against linked issues

Objective Addressed Explanation
Steward creates a directory when trying to open keystore (#251) The changes do not prevent the creation of a directory when trying to open a non-existent keystore, as the methods still rely on a path that may not exist.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 70a78ea and f85e5af.

Files selected for processing (16)
  • src/commands/cosmos_to_eth.rs (1 hunks)
  • src/commands/deploy/erc20.rs (1 hunks)
  • src/commands/eth_to_cosmos.rs (1 hunks)
  • src/commands/keys/cosmos/add.rs (1 hunks)
  • src/commands/keys/cosmos/delete.rs (1 hunks)
  • src/commands/keys/cosmos/recover.rs (1 hunks)
  • src/commands/keys/cosmos/rename.rs (1 hunks)
  • src/commands/keys/cosmos/show.rs (1 hunks)
  • src/commands/keys/eth/add.rs (1 hunks)
  • src/commands/keys/eth/delete.rs (1 hunks)
  • src/commands/keys/eth/import.rs (1 hunks)
  • src/commands/keys/eth/rename.rs (1 hunks)
  • src/commands/keys/eth/show.rs (1 hunks)
  • src/commands/orchestrator/start.rs (1 hunks)
  • src/commands/sign_delegate_keys.rs (1 hunks)
  • src/config.rs (3 hunks)
Additional comments not posted (9)
src/commands/keys/eth/add.rs (1)

27-27: Improved error handling for keystore access.

The change from FsKeyStore::create_or_open(keystore) to FsKeyStore::open(keystore) ensures that the keystore must already exist, preventing the creation of unintended directories. This improves error handling and aligns with the PR objectives.

However, ensure that all function calls to FsKeyStore::open match the new behavior.

Verification successful

Improved error handling for keystore access.

The change from FsKeyStore::create_or_open(keystore) to FsKeyStore::open(keystore) ensures that the keystore must already exist, preventing the creation of unintended directories. This improves error handling and aligns with the PR objectives.

The verification confirms that all instances of FsKeyStore::open in the codebase are appropriately handled, ensuring they match the new behavior.

  • src/config.rs
  • src/commands/keys/eth/rename.rs
  • src/commands/keys/eth/import.rs
  • src/commands/keys/eth/delete.rs
  • src/commands/keys/eth/show.rs
  • src/commands/keys/cosmos/rename.rs
  • src/commands/keys/cosmos/delete.rs
  • src/commands/keys/cosmos/add.rs
  • src/commands/keys/cosmos/recover.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FsKeyStore::open` match the new behavior.

# Test: Search for the function usage. Expect: Only occurances of the new behavior.
rg --type rust -A 5 $'FsKeyStore::open'

Length of output: 4706

src/commands/sign_delegate_keys.rs (1)

23-25: Enhanced error handling for key loading.

The addition of the expect method for the load_clarity_key method ensures that any failure in loading the clarity key is explicitly handled, improving robustness and making debugging easier.

src/commands/keys/cosmos/add.rs (1)

28-28: Improved error handling for keystore access.

The change from FsKeyStore::create_or_open(keystore) to FsKeyStore::open(keystore) ensures that the keystore must already exist, preventing the creation of unintended directories. This improves error handling and aligns with the PR objectives.

However, ensure that all function calls to FsKeyStore::open match the new behavior.

Verification successful

Improved error handling for keystore access.

The change from FsKeyStore::create_or_open(keystore) to FsKeyStore::open(keystore) ensures that the keystore must already exist, preventing the creation of unintended directories. This improves error handling and aligns with the PR objectives. All function calls to FsKeyStore::open match the new behavior.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FsKeyStore::open` match the new behavior.

# Test: Search for the function usage. Expect: Only occurances of the new behavior.
rg --type rust -A 5 $'FsKeyStore::open'

Length of output: 4706

src/commands/deploy/erc20.rs (1)

47-49: LGTM!

The change to add an expect method to handle errors when loading the Ethereum wallet ensures that any failure will be immediately reported. This enhances the robustness of the code.

src/commands/eth_to_cosmos.rs (1)

49-51: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to load_ethers_wallet handle errors appropriately.

Verification successful

Verified: All calls to load_ethers_wallet handle errors appropriately.

The expect calls ensure that any errors in loading the Ethereum wallet are caught and reported with clear messages.

  • src/commands/eth_to_cosmos.rs
  • src/commands/orchestrator/start.rs
  • src/commands/deploy/erc20.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_ethers_wallet` handle errors appropriately.

# Test: Search for the function usage. Expect: Only occurances with error handling.
rg --type rust -A 5 $'load_ethers_wallet'

Length of output: 1539

src/commands/orchestrator/start.rs (2)

50-52: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to load_ethers_wallet handle errors appropriately.

Verification successful

All instances of load_ethers_wallet handle errors appropriately with .expect.

  • src/commands/eth_to_cosmos.rs
  • src/commands/orchestrator/start.rs
  • src/commands/deploy/erc20.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_ethers_wallet` handle errors appropriately.

# Test: Search for the function usage. Expect: Only occurances with error handling.
rg --type rust -A 5 $'load_ethers_wallet'

Length of output: 1539


45-47: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to load_gravity_deep_space_key handle errors appropriately.

Verification successful

All instances of load_gravity_deep_space_key handle errors appropriately.

The function load_gravity_deep_space_key is used in:

  • src/commands/cosmos_to_eth.rs
  • src/commands/orchestrator/start.rs

In both instances, the function calls are followed by expect, ensuring proper error handling.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_gravity_deep_space_key` handle errors appropriately.

# Test: Search for the function usage. Expect: Only occurances with error handling.
rg --type rust -A 5 $'load_gravity_deep_space_key'

Length of output: 1397

src/commands/cosmos_to_eth.rs (1)

67-69: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to load_gravity_deep_space_key handle errors appropriately.

Verification successful

Error handling for load_gravity_deep_space_key is appropriately managed.

All instances of load_gravity_deep_space_key in the codebase handle errors using expect, ensuring consistent and clear error messages.

  • src/commands/cosmos_to_eth.rs
  • src/commands/orchestrator/start.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_gravity_deep_space_key` handle errors appropriately.

# Test: Search for the function usage. Expect: Only occurances with error handling.
rg --type rust -A 5 $'load_gravity_deep_space_key'

Length of output: 1397

src/config.rs (1)

59-86: Enhanced error handling and return type modification approved.

The changes improve robustness by handling various error cases related to the keystore path and wrapping them in a custom error type, preventing panics.

However, ensure that all function calls to load_secret_key handle the new Result type appropriately.

Verification successful

All function calls to load_secret_key handle the new Result type appropriately.

The usage of the ? operator ensures that errors are correctly propagated, confirming that the changes have been integrated properly.

  • src/config.rs: Lines where load_secret_key is called and the Result type is handled.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_secret_key` handle the new `Result` type appropriately.

# Test: Search for the function usage. Expect: Only occurances handling the `Result` type.
rg --type rust -A 5 $'load_secret_key'

Length of output: 1669


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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: 3

Outside diff range, codebase verification and nitpick comments (10)
src/commands/keys/eth/delete.rs (1)

19-19: Ensure proper error handling for non-existent keystore

The run method in DeleteKeyCmd does not handle the potential error of a non-existent keystore gracefully. It uses expect which will cause the program to panic if the keystore cannot be opened. To address this, modify the code to handle the error properly, such as using a match statement or Result handling.

  • File: src/commands/keys/eth/delete.rs
  • Lines: 19-19
Analysis chain

Ensure the keystore exists before running the command.

The change from FsKeyStore::create_or_open to FsKeyStore::open requires the keystore to exist beforehand. This aligns with the PR objectives to prevent unintended directory creation.

However, ensure that all usages of this command handle the potential error of a non-existent keystore gracefully.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `DeleteKeyCmd` handle the potential error of a non-existent keystore gracefully.

# Test: Search for the usage of `DeleteKeyCmd`. Expect: Proper error handling for non-existent keystore.
rg --type rust -A 5 $'DeleteKeyCmd'

Length of output: 957


Script:

#!/bin/bash
# Description: Retrieve the full implementation of the `run` method in `DeleteKeyCmd` and any other places where `DeleteKeyCmd` is invoked.

# Get the full implementation of the `run` method in `DeleteKeyCmd`
ast-grep --lang rust --pattern $'impl Runnable for DeleteKeyCmd {
  fn run(&self) {
    $$$
  }
}' 

# Search for invocations of `DeleteKeyCmd` to check for error handling
rg --type rust 'DeleteKeyCmd'

Length of output: 1053

src/commands/keys/cosmos/delete.rs (1)

20-20: Ensure the keystore exists before running the command.

The change from FsKeyStore::create_or_open to FsKeyStore::open requires the keystore to exist beforehand. This aligns with the PR objectives to prevent unintended directory creation.

However, the current implementation of DeleteCosmosKeyCmd does not handle the potential error of a non-existent keystore gracefully. The use of expect will cause the program to panic if the keystore does not exist.

  • File: src/commands/keys/cosmos/delete.rs
    • Line 20: let keystore = signatory::FsKeyStore::open(keystore).expect("Could not open keystore");

Please add proper error handling to manage this scenario gracefully.

Analysis chain

Ensure the keystore exists before running the command.

The change from FsKeyStore::create_or_open to FsKeyStore::open requires the keystore to exist beforehand. This aligns with the PR objectives to prevent unintended directory creation.

However, ensure that all usages of this command handle the potential error of a non-existent keystore gracefully.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `DeleteCosmosKeyCmd` handle the potential error of a non-existent keystore gracefully.

# Test: Search for the usage of `DeleteCosmosKeyCmd`. Expect: Proper error handling for non-existent keystore.
rg --type rust -A 5 $'DeleteCosmosKeyCmd'

Length of output: 1239


Script:

#!/bin/bash
# Description: Search for all usages of `DeleteCosmosKeyCmd` to verify error handling for non-existent keystore.

# Find all instances where `DeleteCosmosKeyCmd` is used.
rg --type rust 'DeleteCosmosKeyCmd'

Length of output: 244


Script:

#!/bin/bash
# Description: Gather surrounding lines for `DeleteCosmosKeyCmd` usages to verify error handling for non-existent keystore.

# Get surrounding lines for the `Delete` variant in `cosmos.rs`.
rg --type rust -A 10 -B 10 'Delete(delete::DeleteCosmosKeyCmd)' src/commands/keys/cosmos.rs

# Get surrounding lines for the `Runnable` implementation in `delete.rs`.
rg --type rust -A 10 -B 10 'impl Runnable for DeleteCosmosKeyCmd' src/commands/keys/cosmos/delete.rs

Length of output: 937

src/commands/keys/cosmos/show.rs (1)

18-20: Enhance error handling for key loading.

The current implementation of ShowCosmosKeyCmd does not handle the potential error of a non-existent key gracefully. The usage of expect in the run method causes the program to panic on error, which is not ideal.

Please ensure that all usages of ShowCosmosKeyCmd handle errors gracefully. Specifically, update the following files to include proper error handling:

  • src/commands/keys/cosmos/recover.rs
  • src/commands/keys/cosmos/list.rs
  • src/commands/keys/cosmos/add.rs

Consider using match or the ? operator to handle errors and provide meaningful feedback to the user.

Analysis chain

Enhance error handling for key loading.

The addition of expect for the load_deep_space_key method ensures that any failure in loading the key is explicitly handled, providing clearer feedback during runtime.

However, ensure that all usages of this command handle the potential error of a non-existent key gracefully.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `ShowCosmosKeyCmd` handle the potential error of a non-existent key gracefully.

# Test: Search for the usage of `ShowCosmosKeyCmd`. Expect: Proper error handling for non-existent key.
rg --type rust -A 5 $'ShowCosmosKeyCmd'

Length of output: 2899


Script:

#!/bin/bash
# Extract context around the usage of `show_cmd.run()` in `src/commands/keys/cosmos/recover.rs`
rg --type rust -A 10 -B 10 'show_cmd.run()' src/commands/keys/cosmos/recover.rs

# Extract context around the usage of `show_cmd.run()` in `src/commands/keys/cosmos/list.rs`
rg --type rust -A 10 -B 10 'show_cmd.run()' src/commands/keys/cosmos/list.rs

# Extract context around the usage of `show_cmd.run()` in `src/commands/keys/cosmos/add.rs`
rg --type rust -A 10 -B 10 'show_cmd.run()' src/commands/keys/cosmos/add.rs

Length of output: 1748

src/commands/keys/eth/show.rs (1)

21-21: Ensure the keystore exists before running this command.

The change from FsKeyStore::create_or_open to FsKeyStore::open means that the keystore must exist. If the keystore does not exist, this will cause the command to fail. Consider adding a check or a user-friendly error message if the keystore is not found. The following files have instances where FsKeyStore::open is used without proper error handling:

  • src/commands/keys/eth/rename.rs
  • src/commands/keys/eth/import.rs
  • src/commands/keys/eth/delete.rs
  • src/commands/keys/eth/add.rs
  • src/commands/keys/cosmos/recover.rs
  • src/commands/keys/cosmos/rename.rs
  • src/commands/keys/cosmos/add.rs
  • src/commands/keys/eth/show.rs
  • src/commands/keys/cosmos/delete.rs
Analysis chain

Ensure the keystore exists before running this command.

The change from FsKeyStore::create_or_open to FsKeyStore::open means that the keystore must exist. If the keystore does not exist, this will cause the command to fail. Consider adding a check or a user-friendly error message if the keystore is not found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FsKeyStore::open` and ensure proper error handling.

# Test: Search for the function usage. Expect: Proper error handling for missing keystore.
rg --type rust -A 5 $'FsKeyStore::open'

Length of output: 4706

src/commands/keys/eth/rename.rs (1)

26-26: Ensure proper error handling for keystore existence

The change from FsKeyStore::create_or_open to FsKeyStore::open means the keystore must exist, otherwise the command will fail. Here are the instances where FsKeyStore::open is used without adequate error handling:

  • src/commands/keys/cosmos/delete.rs
  • src/commands/keys/eth/show.rs
  • src/commands/keys/eth/import.rs
  • src/commands/keys/cosmos/add.rs
  • src/commands/keys/eth/delete.rs
  • src/commands/keys/eth/add.rs
  • src/commands/keys/eth/rename.rs
  • src/commands/keys/cosmos/rename.rs
  • src/commands/keys/cosmos/recover.rs

Consider adding checks or user-friendly error messages in these locations to handle the scenario where the keystore does not exist.

Analysis chain

Ensure the keystore exists before running this command.

The change from FsKeyStore::create_or_open to FsKeyStore::open means that the keystore must exist. If the keystore does not exist, this will cause the command to fail. Consider adding a check or a user-friendly error message if the keystore is not found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FsKeyStore::open` and ensure proper error handling.

# Test: Search for the function usage. Expect: Proper error handling for missing keystore.
rg --type rust -A 5 $'FsKeyStore::open'

Length of output: 4706

src/commands/keys/cosmos/rename.rs (1)

26-26: Ensure the keystore exists before running this command.

The change from FsKeyStore::create_or_open to FsKeyStore::open means that the keystore must exist. If the keystore does not exist, this will cause the command to fail. Consider adding a check or a user-friendly error message if the keystore is not found.

  • In src/commands/keys/cosmos/rename.rs, the keystore is opened using unwrap(), which will cause a panic if the keystore does not exist. This should be handled more gracefully to improve user experience.
Analysis chain

Ensure the keystore exists before running this command.

The change from FsKeyStore::create_or_open to FsKeyStore::open means that the keystore must exist. If the keystore does not exist, this will cause the command to fail. Consider adding a check or a user-friendly error message if the keystore is not found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `FsKeyStore::open` and ensure proper error handling.

# Test: Search for the function usage. Expect: Proper error handling for missing keystore.
rg --type rust -A 5 $'FsKeyStore::open'

Length of output: 4706

src/config.rs (4)

89-98: Improper handling of Result type in load_clarity_key function calls.

The call to load_clarity_key in src/commands/sign_delegate_keys.rs uses expect, which can cause a panic. Ensure all calls to load_clarity_key handle the Result type appropriately without using expect.

  • src/commands/sign_delegate_keys.rs (line 2): .expect("failed to load key")
Analysis chain

Enhanced error handling and return type modification approved.

The changes improve robustness by handling errors related to key conversion and wrapping them in a custom error type, preventing panics.

However, ensure that all function calls to load_clarity_key handle the new Result type appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_clarity_key` handle the new `Result` type appropriately.

# Test: Search for the function usage. Expect: Only occurances handling the `Result` type.
rg --type rust -A 5 $'load_clarity_key'

Length of output: 872


127-128: Improve error handling for load_ethers_wallet function calls.

The current implementation uses expect on the Result type returned by load_ethers_wallet, which can cause the program to panic if an error occurs. It is recommended to handle the error more gracefully.

  • Files and lines to update:
    • src/commands/orchestrator/start.rs line 127
    • src/commands/eth_to_cosmos.rs line 127
    • src/commands/deploy/erc20.rs line 127
Analysis chain

Return type modification approved.

The change enhances error handling by returning a Result type, preventing panics.

However, ensure that all function calls to load_ethers_wallet handle the new Result type appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_ethers_wallet` handle the new `Result` type appropriately.

# Test: Search for the function usage. Expect: Only occurances handling the `Result` type.
rg --type rust -A 5 $'load_ethers_wallet'

Length of output: 1539


101-111: Improper handling of the Result type detected.

The function load_deep_space_key is used in two instances where the expect method is called, which will cause the program to panic if an error occurs. This is not ideal for robust error handling.

  • src/config.rs
  • src/commands/keys/cosmos/show.rs

Please replace the expect calls with proper error handling logic to ensure robustness.

Analysis chain

Enhanced error handling and return type modification approved.

The changes improve robustness by handling errors related to key parsing and wrapping them in a custom error type, preventing panics.

However, ensure that all function calls to load_deep_space_key handle the new Result type appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_deep_space_key` handle the new `Result` type appropriately.

# Test: Search for the function usage. Expect: Only occurances handling the `Result` type.
rg --type rust -A 5 $'load_deep_space_key'

Length of output: 1104


114-124: Inappropriate use of .expect() for handling Result type.

The function calls to load_gravity_deep_space_key in the following files use .expect(), which causes the program to panic if an error occurs. This is not ideal for robust error handling. Please update these instances to properly handle the Result type without causing a panic.

  • src/commands/cosmos_to_eth.rs
  • src/commands/orchestrator/start.rs

Consider using pattern matching or other error handling mechanisms like unwrap_or_else or ? operator in a context that returns a Result.

Analysis chain

Enhanced error handling and return type modification approved.

The changes improve robustness by handling errors related to key parsing and wrapping them in a custom error type, preventing panics.

However, ensure that all function calls to load_gravity_deep_space_key handle the new Result type appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `load_gravity_deep_space_key` handle the new `Result` type appropriately.

# Test: Search for the function usage. Expect: Only occurances handling the `Result` type.
rg --type rust -A 5 $'load_gravity_deep_space_key'

Length of output: 1397

@@ -28,7 +28,7 @@ impl Runnable for RecoverCosmosKeyCmd {
fn run(&self) {
let config = APP.config();
let keystore = path::Path::new(&config.keystore);
let keystore = FsKeyStore::create_or_open(keystore).expect("Could not open keystore");
let keystore = FsKeyStore::open(keystore).expect("Could not open keystore");
Copy link

Choose a reason for hiding this comment

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

Verify the existence of the keystore before opening it.

The change to use FsKeyStore::open(keystore) ensures that only existing keystores are accessed. However, this might lead to an error if the keystore does not exist. Consider adding a check to verify the existence of the keystore before attempting to open it.

if !keystore.exists() {
    eprintln!("Keystore does not exist, exiting.");
    return;
}
let keystore = FsKeyStore::open(keystore).expect("Could not open keystore");

@@ -28,7 +28,7 @@ impl Runnable for ImportEthKeyCmd {
fn run(&self) {
let config = APP.config();
let keystore = path::Path::new(&config.keystore);
let keystore = FsKeyStore::create_or_open(keystore).expect("Could not open keystore");
let keystore = FsKeyStore::open(keystore).expect("Could not open keystore");
Copy link

Choose a reason for hiding this comment

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

Verify the existence of the keystore before opening it.

The change to use FsKeyStore::open(keystore) ensures that only existing keystores are accessed. However, this might lead to an error if the keystore does not exist. Consider adding a check to verify the existence of the keystore before attempting to open it.

if !keystore.exists() {
    eprintln!("Keystore does not exist, exiting.");
    return;
}
let keystore = FsKeyStore::open(keystore).expect("Could not open keystore");

src/config.rs Show resolved Hide resolved
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.

Steward creates a directory when trying to open keystore
2 participants