Skip to content

Conversation

@agaffney
Copy link
Contributor

@agaffney agaffney commented Dec 3, 2025

Fixes #457


Summary by cubic

Prevents decoding empty resource data in Handshake register/update covenants to avoid errors when resource bytes are missing. Also adds clearer error messages when decoding domain resource data.

  • Bug Fixes
    • Decode resource data only when bytes are present in gc.Items[2].
    • Add context to errors in NewUpdateCovenantFromGeneric.
    • Wrap version, record type, and record decode errors in DomainResourceData.decode with helpful context.
    • Stop processing on unknown record types instead of error to match hsd.

Written for commit 66e5805. Summary will update automatically on new commits.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected handling of optional resource data so absent data no longer triggers decoding errors.
    • Stopped further decoding when encountering unsupported record types to avoid processing invalid records.
  • Chores

    • Improved and standardized error messages with additional context to aid diagnostics.

✏️ Tip: You can customize this high-level summary in your review settings.

@agaffney agaffney requested a review from a team as a code owner December 3, 2025 01:44
@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

📝 Walkthrough

Walkthrough

Decoding of resource data in NewRegisterCovenantFromGeneric and NewUpdateCovenantFromGeneric is now conditional: the code only attempts to decode and assign ResourceData when gc.Items[2] has non-zero length. DomainResourceData.decode now wraps errors for version reads, record-type reads, and record decoding; it also uses a loop label and breaks out when encountering an unknown record type instead of returning an error. Public APIs and exported declarations are unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect handshake/covenant.go changes to ensure gc.Items[2] length checks cover all edge cases and that ResourceData is assigned correctly when present.
  • Review handshake/domain.go changes: verify error wrapping messages are correct and that the new break-on-unknown-record behavior is intended and safe for all record streams.
  • Check call sites that rely on ResourceData being present to ensure they handle its absence gracefully.
  • Confirm tests (or add new ones) for covenants with empty and non-empty gc.Items[2], and for unknown record types in domain decoding.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main fix: preventing decoding of empty resource data in covenants, which is the core issue being addressed.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #457: it prevents decoding empty resource data to avoid EOF errors and adds contextual error messages for better diagnostics.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the covenant resource data decoding issue and improving error handling in domain resource data parsing, with no unrelated modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/handshake-covenant-resdata

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5a227f and 66e5805.

📒 Files selected for processing (2)
  • handshake/covenant.go (2 hunks)
  • handshake/domain.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • handshake/covenant.go
⏰ 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)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
handshake/domain.go (3)

72-74: LGTM!

Error wrapping with contextual message improves debuggability when decoding fails.


78-106: Behavior change to stop on unknown record type looks correct.

The switch from returning an error to breaking the loop on unknown record types matches hsd behavior per the comment. This is a more lenient approach that allows partial decoding to succeed. The loop label pattern is idiomatic Go.

Note that any trailing bytes after an unknown record type will be silently discarded. If this needs auditing/logging in the future, consider adding a debug log here.


107-111: LGTM!

Error wrapping provides context when record decoding fails, creating a useful error chain for diagnosis.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
handshake/covenant.go (1)

396-402: LGTM! Fixes the Update covenant EOF panic.

The conditional check prevents the EOF panic mentioned in issue #457. The error wrapping provides helpful context if decoding fails.

Minor inconsistency: NewRegisterCovenantFromGeneric (lines 358-364) doesn't wrap its decode error, while this function does. Consider adding similar error wrapping to the Register covenant for consistency.

Apply this diff to add consistent error wrapping to NewRegisterCovenantFromGeneric:

 	if len(gc.Items[2]) > 0 {
 		tmpData, err := NewDomainResourceDataFromBytes(gc.Items[2])
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("decode domain resource data: %w", err)
 		}
 		ret.ResourceData = *tmpData
 	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3419ed5 and d5a227f.

📒 Files selected for processing (2)
  • handshake/covenant.go (2 hunks)
  • handshake/domain.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
handshake/covenant.go (1)
handshake/domain.go (1)
  • NewDomainResourceDataFromBytes (60-66)
⏰ 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). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
handshake/domain.go (1)

73-73: LGTM! Error wrapping improves diagnostics.

The added error wrapping provides valuable context about which decoding step failed (version read, record type read, or record decode), making it easier to diagnose issues like the EOF panic described in #457.

Also applies to: 84-84, 107-107

handshake/covenant.go (1)

358-364: LGTM! Prevents EOF panic on empty resource data.

The conditional check prevents attempting to decode empty resource data, which was causing the EOF panic described in issue #457. When gc.Items[2] is empty, ResourceData remains as its zero value, which is appropriate.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Fixes #457

Signed-off-by: Aurora Gaffney <aurora@blinklabs.io>
@agaffney agaffney force-pushed the fix/handshake-covenant-resdata branch from d5a227f to 66e5805 Compare December 3, 2025 03:42
@agaffney agaffney merged commit 31ca56e into main Dec 3, 2025
10 checks passed
@agaffney agaffney deleted the fix/handshake-covenant-resdata branch December 3, 2025 12:31
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.

Failure converting Handshake generic covenant to Update

3 participants