Skip to content

sv1: return errors instead of panicking in MerkleNode TryFrom#2084

Merged
GitGab19 merged 1 commit intostratum-mining:mainfrom
ashishkrshaw:fix/sv1-merkle-node-error-handling
Feb 16, 2026
Merged

sv1: return errors instead of panicking in MerkleNode TryFrom#2084
GitGab19 merged 1 commit intostratum-mining:mainfrom
ashishkrshaw:fix/sv1-merkle-node-error-handling

Conversation

@ashishkrshaw
Copy link
Copy Markdown
Contributor

@ashishkrshaw ashishkrshaw commented Feb 14, 2026

What this PR does

While reading sv1/src/utils.rs, I noticed that MerkleNode parsing used unwrap() in two TryFrom implementations.
That means bad input could panic instead of returning a normal error.

This PR replaces those unwrap() calls with proper error handling, so invalid input returns Err safely.

Changes made

  • Updated:
    • TryFrom<Vec<u8>> for MerkleNode
    • TryFrom<&str> for MerkleNode
  • Added tests for invalid input length:
    • merkle_node_try_from_vec_invalid_len_returns_err
    • merkle_node_try_from_str_invalid_len_returns_err

Why this helps

TryFrom should fail gracefully, not panic.
This makes the API behavior safer and more predictable for callers.

Notes

This is my beginner contribution, so I kept the change small and focused.
Happy to improve anything based on review feedback.

@GitGab19 GitGab19 merged commit cac1059 into stratum-mining:main Feb 16, 2026
16 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.

3 participants