Skip to content

fix: initialize entries slice in NewTransferHistory - #119

Closed
saurabhhhcodes wants to merge 1 commit into
PranavAgarkar07:mainfrom
saurabhhhcodes:fix/nil-slice-init-history
Closed

fix: initialize entries slice in NewTransferHistory#119
saurabhhhcodes wants to merge 1 commit into
PranavAgarkar07:mainfrom
saurabhhhcodes:fix/nil-slice-init-history

Conversation

@saurabhhhcodes

@saurabhhhcodes saurabhhhcodes commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

NewTransferHistory did not initialize the entries slice, leaving it nil. While the Add function handled nil entries lazily, initializing in the constructor is safer and follows Go best practices.

Summary by CodeRabbit

  • Bug Fixes
    • Improved transfer history initialization to ensure history entries are available immediately and behave consistently when adding or listing transfers.

NewTransferHistory did not initialize the entries slice, leaving it nil.
While the Add function handled nil entries lazily, initializing in the
constructor is safer and follows Go best practices.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 65b24495-dc9c-4ab3-bfb2-8704c440923d

📥 Commits

Reviewing files that changed from the base of the PR and between 8f9f981 and ce98671.

📒 Files selected for processing (1)
  • beamsync/history.go

📝 Walkthrough

Walkthrough

NewTransferHistory now initializes the entries slice when constructing a TransferHistory, using maxEntries as its length instead of deferring allocation.

Changes

Transfer history initialization

Layer / File(s) Summary
Initialize transfer entries
beamsync/history.go
NewTransferHistory now creates the entries slice with maxEntries elements during construction.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: initializing the entries slice in NewTransferHistory.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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.

@PranavAgarkar07

Copy link
Copy Markdown
Owner

Closing this PR. The nil entries slice is not a bug — Add() already handles lazy initialization at history.go:75-77 and List() checks h.count (which starts at 0). The proposed fix also introduces dead code (the lazy init in Add becomes unreachable). This is a YAGNI case: the existing code works correctly.

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.

2 participants