fix: more consistent panic strings (#678)

* lint: pin golangci-lint version

* fix: more consistent panic strings

* Update golangci-lint version in workflow

Updated golangci-lint action version to v2.4.

---------

Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
This commit is contained in:
Nathan Baulch
2025-09-25 05:02:02 +10:00
committed by GitHub
parent 3e11f11781
commit b5e290abe0
8 changed files with 13 additions and 13 deletions

View File

@@ -20,7 +20,7 @@ func (s *synchronize) Do(cb func()) {
// Play: https://go.dev/play/p/X3cqROSpQmu
func Synchronize(opt ...sync.Locker) *synchronize { //nolint:revive
if len(opt) > 1 {
panic("unexpected arguments")
panic("lo.Synchronize: unexpected arguments")
} else if len(opt) == 0 {
opt = append(opt, &sync.Mutex{})
}

View File

@@ -55,7 +55,7 @@ func TestSynchronize(t *testing.T) {
// check we don't accept multiple arguments
{
is.PanicsWithValue("unexpected arguments", func() {
is.PanicsWithValue("lo.Synchronize: unexpected arguments", func() {
mu := &sync.Mutex{}
Synchronize(mu, mu, mu)
})

2
map.go
View File

@@ -252,7 +252,7 @@ func Assign[K comparable, V any, Map ~map[K]V](maps ...Map) Map {
// Play: https://go.dev/play/p/X_YQL6mmoD-
func ChunkEntries[K comparable, V any](m map[K]V, size int) []map[K]V {
if size <= 0 {
panic("The chunk size must be greater than 0")
panic("lo.ChunkEntries: size must be greater than 0")
}
count := len(m)

View File

@@ -354,10 +354,10 @@ func TestChunkEntries(t *testing.T) {
is.Len(result4, expectedCount4)
is.Len(result5, expectedCount5)
is.PanicsWithValue("The chunk size must be greater than 0", func() {
is.PanicsWithValue("lo.ChunkEntries: size must be greater than 0", func() {
ChunkEntries(map[string]int{"a": 1}, 0)
})
is.PanicsWithValue("The chunk size must be greater than 0", func() {
is.PanicsWithValue("lo.ChunkEntries: size must be greater than 0", func() {
ChunkEntries(map[string]int{"a": 1}, -1)
})

View File

@@ -208,7 +208,7 @@ func GroupByMap[T any, K comparable, V any](collection []T, iteratee func(item T
// Play: https://go.dev/play/p/kEMkFbdu85g
func Chunk[T any, Slice ~[]T](collection Slice, size int) []Slice {
if size <= 0 {
panic("Second parameter must be greater than 0")
panic("lo.Chunk: size must be greater than 0")
}
chunksNum := len(collection) / size

View File

@@ -318,7 +318,7 @@ func TestChunk(t *testing.T) {
is.Equal([][]int{{0, 1}, {2, 3}, {4, 5}, {6}}, result2)
is.Equal([][]int{}, result3)
is.Equal([][]int{{0}}, result4)
is.PanicsWithValue("Second parameter must be greater than 0", func() {
is.PanicsWithValue("lo.Chunk: size must be greater than 0", func() {
Chunk([]int{0}, 0)
})

View File

@@ -34,10 +34,10 @@ var (
// Play: https://go.dev/play/p/rRseOQVVum4
func RandomString(size int, charset []rune) string {
if size <= 0 {
panic("lo.RandomString: Size parameter must be greater than 0")
panic("lo.RandomString: size must be greater than 0")
}
if len(charset) == 0 {
panic("lo.RandomString: Charset parameter must not be empty")
panic("lo.RandomString: charset must not be empty")
}
// see https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
@@ -118,7 +118,7 @@ func Substring[T ~string](str T, offset int, length uint) T {
// Play: https://go.dev/play/p/__FLTuJVz54
func ChunkString[T ~string](str T, size int) []T {
if size <= 0 {
panic("lo.ChunkString: Size parameter must be greater than 0")
panic("lo.ChunkString: size must be greater than 0")
}
if len(str) == 0 {

View File

@@ -27,8 +27,8 @@ func TestRandomString(t *testing.T) {
is.Equal(100, RuneLength(str3))
is.Subset(noneUtf8Charset, []rune(str3))
is.PanicsWithValue("lo.RandomString: Charset parameter must not be empty", func() { RandomString(100, []rune{}) })
is.PanicsWithValue("lo.RandomString: Size parameter must be greater than 0", func() { RandomString(0, LowerCaseLettersCharset) })
is.PanicsWithValue("lo.RandomString: charset must not be empty", func() { RandomString(100, []rune{}) })
is.PanicsWithValue("lo.RandomString: size must be greater than 0", func() { RandomString(0, LowerCaseLettersCharset) })
}
func TestChunkString(t *testing.T) {
@@ -53,7 +53,7 @@ func TestChunkString(t *testing.T) {
result6 := ChunkString("明1好休2林森", 2)
is.Equal([]string{"明1", "好休", "2林", "森"}, result6)
is.Panics(func() {
is.PanicsWithValue("lo.ChunkString: size must be greater than 0", func() {
ChunkString("12345", 0)
})
}