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: finish removing unwraps #2881

Merged
merged 3 commits into from
Nov 1, 2023

Conversation

daniel-savu
Copy link
Contributor

Description

  • Removes unwraps and expects from everywhere but run-locally
  • Precomputes the address in Signer at construction time, to propagate the error early and keep signatures ergonomic by not requiring a Result. Couldn't also precompile SigningKey (the privkey type) because it's not Sync 😢
  • Defines a hyperlane-cosmos-specific error enum (HyperlaneCosmosError), which can be converted to ChainCommunicationError with the ? operator. This is a pattern we'd like to refactor towards in the future, to remove dependencies from hyperlane-core as much as possible
    • One inconvenience is that you need to .map_err() to HyperlaneCosmosError first, to use ?. I wish ? had deref coercion semantics where it'd keep covnerting until an error matches, but I assume this isn't possible because while you can only have a single Deref impl, you can have multiple From<Err> impls.
    • Writing this I'm realising we could write a small macro to implement From<Err> for ChainCommunicationError for all the sub-errors of HyperlaneCosmosError et al (cc @tkporter)

Copy link
Collaborator

@tkporter tkporter left a comment

Choose a reason for hiding this comment

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

🔥

// use bech32::Error;
use hyperlane_core::ChainCommunicationError;

/// Errors from the crates specific to the hyperlane-cosmos
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@@ -0,0 +1,22 @@
// use bech32::Error;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: rm

@@ -6,6 +6,7 @@ use std::ops::Deref;
use crate::config::StrOrIntParseError;
use cosmrs::proto::prost;
use cosmrs::Error as CosmrsError;
// use fixed_hash::rustc_hex::FromHexError;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: rm

@daniel-savu daniel-savu merged commit 355c4a8 into trevor/new-featv3-cosmos-oct-28 Nov 1, 2023
2 of 4 checks passed
@daniel-savu daniel-savu deleted the dan/rm-unwrap branch November 1, 2023 18:13
yorhodes pushed a commit that referenced this pull request Nov 2, 2023
### Description

- Removes unwraps and expects from everywhere but `run-locally`
- Precomputes the `address` in `Signer` at construction time, to
propagate the error early and keep signatures ergonomic by not requiring
a `Result`. Couldn't also precompile `SigningKey` (the privkey type)
because it's not `Sync` 😢
- Defines a `hyperlane-cosmos`-specific error enum
(`HyperlaneCosmosError`), which can be converted to
`ChainCommunicationError` with the `?` operator. This is a pattern we'd
like to refactor towards in the future, to remove dependencies from
`hyperlane-core` as much as possible
- One inconvenience is that you need to `.map_err()` to
`HyperlaneCosmosError` first, to use `?`. I wish `?` had deref coercion
semantics where it'd keep covnerting until an error matches, but I
assume this isn't possible because while you can only have a single
`Deref` impl, you can have multiple `From<Err>` impls.
- Writing this I'm realising we could write a small macro to implement
`From<Err> for ChainCommunicationError` for all the sub-errors of
`HyperlaneCosmosError` et al (cc @tkporter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants