Skip to content

Handle empty cache while using Range or RangeBackwards#176

Merged
davseby merged 1 commit intov3from
range-panics
May 25, 2025
Merged

Handle empty cache while using Range or RangeBackwards#176
davseby merged 1 commit intov3from
range-panics

Conversation

@davseby
Copy link
Copy Markdown
Contributor

@davseby davseby commented May 25, 2025

After adding this snippet:

deletedCache := New[string, string]()
addToCache(deletedCache, time.Minute, "6", "3", "4")
assert.NotPanics(t, func() {
	deletedCache.Range(func(item *Item[string, string]) bool {
		deletedCache.DeleteAll()
		return true
	})
})

I received a panic as the check part of the loop assumed that the cache wouldn't be empty. A simple len check fixes this.

Closes #174.

@davseby davseby requested a review from swithek May 25, 2025 11:37
@davseby davseby self-assigned this May 25, 2025
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 15237467069

Details

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 99.711%

Totals Coverage Status
Change from base Build 14738370205: 0.3%
Covered Lines: 689
Relevant Lines: 691

💛 - Coveralls

@davseby davseby merged commit 999c0b9 into v3 May 25, 2025
4 checks passed
@davseby davseby deleted the range-panics branch May 25, 2025 11:40
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.

Panic in RangeBackwards

3 participants