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

Improve network error handling #148

Merged
merged 5 commits into from
Feb 19, 2025

Conversation

diegomrsantos
Copy link

@diegomrsantos diegomrsantos commented Feb 18, 2025

Issue Addressed

closes #75

Proposed Changes

This PR aims to improve network error handling. The key technical changes proposed include:

  • Enhanced Error Handling: Introduces specific error types for various network-related errors in the Discovery and Network modules using thiserror.
  • Detailed Error Messages: Provides more detailed and user-friendly error messages for issues like ENR key parsing, ENR building, and Discv5 initialization and startup errors.
  • Refactoring: Splits complex expressions into multiple lines for better readability and error handling, particularly around await calls and error mappings.
  • Error Propagation: Ensures that errors are properly propagated and handled in asynchronous functions, converting generic errors into specific ones.

@diegomrsantos diegomrsantos changed the title improve network error handling Improve network error handling Feb 18, 2025
@diegomrsantos diegomrsantos force-pushed the improve-network-error-handling branch from b41027f to 3aa2b49 Compare February 18, 2025 16:27
@diegomrsantos diegomrsantos force-pushed the improve-network-error-handling branch from 3aa2b49 to e33f28b Compare February 18, 2025 16:30
Comment on lines 50 to 62
pub enum DiscoveryError {
#[error("Failed to parse keypair into an ENR key: {0}")]
EnrKey(String),

#[error("Failed to build ENR: {0}")]
EnrBuild(String),

#[error("Discv5 initialization error: {0}")]
Discv5Init(String),

#[error("Discv5 start error: {0}")]
Discv5Start(String),
}
Copy link
Member

Choose a reason for hiding this comment

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

Do these all need to be String? Actual error types should be a bit clearer and should not affect the displayed message as the format string uses the Display impl of the inner type, which is the same thing as the to_string that you manually call below.

Copy link
Author

@diegomrsantos diegomrsantos Feb 18, 2025

Choose a reason for hiding this comment

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

Do you mean the original error? If so, that's the type of the original errors, like in https://github.com/sigp/lighthouse/blob/stable/beacon_node/lighthouse_network/src/discovery/enr_ext.rs#L281

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, thanks. I changed it for EnrBuild and I'll double-check the others.

Copy link
Author

Choose a reason for hiding this comment

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

Hopefully I covered everything now

bitfield.set(9, true).unwrap();

builder.add_value::<Bytes>("subnets", &bitfield.as_ssz_bytes().into());
builder.add_value::<Bytes>("subnets", &BitVector::<U128>::new().as_ssz_bytes().into());
Copy link
Author

Choose a reason for hiding this comment

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

@dknopik This is about what we talked yesterday. Should we create an empty BitVector at this point?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the subnets will be updates as the subnet tracker messages come in: 9e9e485

Copy link
Member

Choose a reason for hiding this comment

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

as always, open for other suggestions though

Copy link
Author

Choose a reason for hiding this comment

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

From what I understand, it makes sense.

@diegomrsantos diegomrsantos self-assigned this Feb 18, 2025
@diegomrsantos diegomrsantos force-pushed the improve-network-error-handling branch from 423fcbf to 5b3a009 Compare February 18, 2025 20:44
@diegomrsantos diegomrsantos force-pushed the improve-network-error-handling branch from 0d97c23 to 07455cc Compare February 19, 2025 11:08
Copy link
Member

@dknopik dknopik left a comment

Choose a reason for hiding this comment

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

lgtm

@dknopik dknopik merged commit 3958faa into sigp:unstable Feb 19, 2025
10 checks passed
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