refactor: use thiserror for ExecutionError and typed Operator::new error#351
refactor: use thiserror for ExecutionError and typed Operator::new error#351diegomrsantos wants to merge 5 commits intosigp:unstablefrom
Conversation
7f11ba8 to
d6942e0
Compare
There was a problem hiding this comment.
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
ShareParseErrorandRsaParseErrorenums usingthiserrorfor richer error information. - Extended
ExecutionErrorwith 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
EncryptedKeyLengthis passing the literal string "actual" instead of theactualfield; 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(
4ab15e7 to
1b590f6
Compare
dknopik
left a comment
There was a problem hiding this comment.
Thanks for looking into this! I added some early thoughts
|
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]>
791ecb2 to
e5eea70
Compare
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]>
|
maybe create gh issue for this? |
Issue Addressed
Closes #317
Proposed Changes
Improve error handling in the
ethcrate by introducingthiserror, preserving error chains, and removing duplicate logging.ExecutionErrorfrom a manualDisplayimpl tothiserrorderive with human-readable#[error(...)]messagesDecodeErrorvariant fromDecodeError(String)toDecodeError(#[from] alloy::sol_types::Error), preserving the error source chain instead of formatting to stringoperator_key::ConversionErrorfromOperator::newinstead of discarding it via.map_err(|e| e.to_string())debug!()/error!()logs from inside.map_err()closures and beforereturn Err()inevent_processor.rs,sync.rs, andutil.rs— the caller already logs every returned error atwarn/trace(event processing) orerror(sync), so these produced duplicate log entriesAdditional Info
String-wrapping variants (Database,InvalidEvent, etc.) keep their current signatureDisplayformat changes fromDebugoutput (DecodeError("...")) to human-readable (Decode error: ...), which improves log readabilityDatabase) fromStringto typed source errors is a natural follow-up but left out to keep this PR focused