-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add specific error codes for deserialization failures #121
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
base: main
Are you sure you want to change the base?
feat: Add specific error codes for deserialization failures #121
Conversation
Signed-off-by: AvhiMaz <avhimazumder5@outlook.com>
WalkthroughAdded three new DlpError variants for precise deserialization failures and updated serialization/deserialization utilities to return those specific errors and enforce exact data length checks. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-10-15T11:45:25.802ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
src/error.rs(1 hunks)src/state/utils/to_bytes.rs(1 hunks)src/state/utils/try_from_bytes.rs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-28T18:27:42.542Z
Learnt from: snawaz
Repo: magicblock-labs/delegation-program PR: 111
File: src/diff/types.rs:87-102
Timestamp: 2025-10-28T18:27:42.542Z
Learning: In Solana runtime, `account_info.data()` is guaranteed to have 8-byte alignment.
Applied to files:
src/state/utils/to_bytes.rs
🧬 Code graph analysis (1)
src/state/utils/to_bytes.rs (2)
src/state/commit_record.rs (1)
size_of(37-37)src/state/delegation_record.rs (1)
size_of(40-40)
🔇 Additional comments (1)
src/state/utils/to_bytes.rs (1)
9-11: Exact-length check removes panic risk but tightens the API contractComputing
expected_len = 8 + size_of::<Self>()and requiringdata.len() == expected_lenis a good safety improvement: it preventscopy_from_slicefrom panicking on mismatched buffer sizes and surfaces a clearDlpError::InvalidDataLengthinstead.This does slightly tighten behavior versus accepting arbitrary slice lengths, so it’s worth double-checking that all call sites pass exactly-sized buffers (e.g., full account data for these records) and don’t rely on any extra trailing space.
Problem
Deserialization failures all returned the same generic error, making debugging hard.
Solution
Added specific error types for:
Updated macros to use these errors and added a safety check to prevent panics during serialization.
Deploy Notes
Fixes #112
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.