Skip to content

refactor: use thiserror for ExecutionError and typed Operator::new error#351

Open
diegomrsantos wants to merge 5 commits intosigp:unstablefrom
diegomrsantos:improve-log-event-processor
Open

refactor: use thiserror for ExecutionError and typed Operator::new error#351
diegomrsantos wants to merge 5 commits intosigp:unstablefrom
diegomrsantos:improve-log-event-processor

Conversation

@diegomrsantos
Copy link
Member

@diegomrsantos diegomrsantos commented May 29, 2025

Issue Addressed

Closes #317

Proposed Changes

Improve error handling in the eth crate by introducing thiserror, preserving error chains, and removing duplicate logging.

  • Convert ExecutionError from a manual Display impl to thiserror derive with human-readable #[error(...)] messages
  • Change DecodeError variant from DecodeError(String) to DecodeError(#[from] alloy::sol_types::Error), preserving the error source chain instead of formatting to string
  • Return typed operator_key::ConversionError from Operator::new instead of discarding it via .map_err(|e| e.to_string())
  • Remove ~17 duplicate debug!()/error!() logs from inside .map_err() closures and before return Err() in event_processor.rs, sync.rs, and util.rs — the caller already logs every returned error at warn/trace (event processing) or error (sync), so these produced duplicate log entries

Additional Info

  • All existing call sites continue to work unchanged — the String-wrapping variants (Database, InvalidEvent, etc.) keep their current signature
  • The Display format changes from Debug output (DecodeError("...")) to human-readable (Decode error: ...), which improves log readability
  • Converting more variants (e.g. Database) from String to typed source errors is a natural follow-up but left out to keep this PR focused

@diegomrsantos diegomrsantos self-assigned this May 29, 2025
@diegomrsantos diegomrsantos changed the title improve log for event processor Improve log for event processor May 29, 2025
@diegomrsantos diegomrsantos force-pushed the improve-log-event-processor branch 2 times, most recently from 7f11ba8 to d6942e0 Compare June 3, 2025 08:30
@diegomrsantos diegomrsantos requested a review from Copilot June 3, 2025 08:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Enhance error handling and logging by introducing typed error enums for share parsing, RSA parsing, and execution events, and replacing generic error messages with contextual variants.

  • Added ShareParseError and RsaParseError enums using thiserror for richer error information.
  • Extended ExecutionError with specific builders (invalid_operator_event, invalid_validator_event, etc.) and updated call sites accordingly.
  • Updated parsing and sync logic to use the new error variants and removed or adjusted debug log statements.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
eth/src/util.rs Introduced ShareParseError, updated parse_shares to return it.
eth/src/sync.rs Switched to ExecutionError::invalid_event builder for errors.
eth/src/network_actions.rs Added StringError wrapper, updated error constructors.
eth/src/event_processor.rs Replaced generic errors with contextual builders; removed logs.
eth/src/error.rs Expanded ExecutionError with new variants and builder methods.
eth/Cargo.toml Added thiserror as a dependency.
common/ssv_types/src/util.rs Introduced RsaParseError, updated parse_rsa to return it.
common/ssv_types/src/operator.rs Updated Operator::new to surface RsaParseError.
common/ssv_types/src/lib.rs Re-exported RsaParseError.
Comments suppressed due to low confidence (3)

anchor/eth/src/util.rs:37

  • The error annotation for EncryptedKeyLength is passing the literal string "actual" instead of the actual field; change the placeholder to {actual} so the runtime value is shown.
#[error("Encrypted key has wrong length: expected {}, got {}", ENCRYPTED_KEY_LENGTH, "actual")]

anchor/eth/src/event_processor.rs:442

  • The error message "Failed to validator cluster" is grammatically incorrect; consider updating it to something like "Failed to delete validator from cluster: {e}".
.map_err(|e| ExecutionError::Database(format!("Failed to validator cluster: {e}"))?);

anchor/eth/src/util.rs:50

  • [nitpick] New error variants in parse_shares (e.g., InvalidLength, PublicKeyCreation, EncryptedKeyLength) are not covered by existing tests; consider adding unit tests for each failure branch.
pub fn parse_shares(

@diegomrsantos diegomrsantos force-pushed the improve-log-event-processor branch 3 times, most recently from 4ab15e7 to 1b590f6 Compare June 3, 2025 11:05
@diegomrsantos diegomrsantos marked this pull request as ready for review June 3, 2025 11:19
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.

Thanks for looking into this! I added some early thoughts

@diegomrsantos diegomrsantos marked this pull request as draft June 3, 2025 13:47
@Zacholme7
Copy link
Member

We still planning to keep this or is it closable?

@diegomrsantos
Copy link
Member Author

We still planning to keep this or is it closable?

I wanna do it at some point

Replace manual Display impl on ExecutionError with thiserror derive.
Change DecodeError variant to wrap alloy::sol_types::Error via #[from],
preserving the error chain instead of formatting to String. Return typed
operator_key::ConversionError from Operator::new instead of String.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@diegomrsantos diegomrsantos force-pushed the improve-log-event-processor branch from 791ecb2 to e5eea70 Compare March 4, 2026 20:45
@diegomrsantos diegomrsantos changed the title Improve log for event processor refactor: use thiserror for ExecutionError and typed Operator::new error Mar 4, 2026
Remove debug/error logs from inside .map_err() closures and before
return Err() statements in event_processor.rs, sync.rs, and util.rs.
The caller already logs every returned error, so logging at the
construction site caused duplicate log entries (issue sigp#317).

Also fix a typo in an error message ("Failed to validator cluster"
-> "Failed to delete validator") and include the channel error in
the exit request failure message.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@diegomrsantos diegomrsantos marked this pull request as ready for review March 4, 2026 21:27
@diegomrsantos diegomrsantos added the ready-for-review This PR is ready to be reviewed label Mar 5, 2026
@shane-moore
Copy link
Member

maybe create gh issue for this?
Converting more variants (e.g. Database) from String to typed source errors is a natural follow-up but left out to keep this PR focused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore logging ready-for-review This PR is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants