runtime error: makeslice: cap out of range

This issue has been created since 2022-12-25.
  • OS: linux
  • GO Version: 1.19.3
  • Pkg Version: 0.6.1

I use dump.Format(ob) where ob is an interface of struct
then I have error:
runtime error: makeslice: cap out of range

trace is:

Screenshot from 2022-12-25 15-12-24

inhere wrote this answer on 2023-01-14

hi @Mehrdad-Dadkhah

Thanks, can provide an example for ob?

tommynanny wrote this answer on 2023-02-03

I got this error when the code is run in a goroutine (not sure exactly what the cause is, but it happens from time to time, and only happens to that line, all the other places where I use kw.Logger.Println never gives an error)

kw.Logger.Println("KafkaWorker Starts Listening.")  // << the error happens here
!!!!!!!!!!!!!!!![All 2 KafkaWorkers Start Listening...
]PRINT AT anra/go-sim-driver/log.(*ANRALogger).Printf(anra_logger.go:67)
[]interface {} [ #len=1,cap=1
  string("[]interface {} [ #len=1,cap=1
  string("All 2 KafkaWorkers Start Listening...
"), #len=38
],
"), #len=126
],
!!!!!!!!!!!!!!!![KafkaWorker Starts Listening.]PRINT AT anra/go-sim-driver/kafka.(*KafkaWorker).Listen(kafka_worker.go:54)
string("KafkaWorker Starts Listening."), #len=29
!!!!!!!!!!!!!!!![KafkaWorker Starts Listening.]panic: runtime error: makeslice: cap out of range

goroutine 60 [running]:
github.com/gookit/goutil/strutil.RepeatChars[...](0x20?, 0xfffffffffffffffe)
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/strutil/padding.go:167 +0x34
github.com/gookit/goutil/strutil.RepeatBytes(...)
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/strutil/padding.go:158
github.com/gookit/goutil/dump.(*Dumper).advance(...)
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:172
github.com/gookit/goutil/dump.(*Dumper).printRValue(0xc0000b25a0, {0x10b73c0, 0xed54a0}, {0xed54a0?, 0xc0003eea50?, 0xc0001bf020?})
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:263 +0x1ca5
github.com/gookit/goutil/dump.(*Dumper).printOne(0xc0000b25a0, {0xed54a0?, 0xc0003eea50?})
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:190 +0x2f9
github.com/gookit/goutil/dump.(*Dumper).dump(0xc0000b25a0, {0xc0000d5ea8, 0x1, 0xc00008dde8?})
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:124 +0x114
github.com/gookit/goutil/dump.(*Dumper).Fprint(...)
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:97
github.com/gookit/goutil/dump.Format({0xc00008dea8, 0x1, 0x1})
        /home/nanlin/go/pkg/mod/github.com/gookit/[email protected]/dump/dump.go:116 +0x93
go-sim-driver/log.(*SpecialLogger).wrap(0xc00053aa20, {0xc000318a50, 0x1, 0x1})
func (l *SpecialLogger) Println(v ...any) {
	r1, r2 := l.wrap(v...) // << the error happens here
	l.dumpToStdout(r2)
	l.Logger.Println(r1)
}

func (l *SpecialLogger) wrap(raw ...any) (logString string, stdString string) {
	if !l.UseWrapper {
		return fmt.Sprint(raw...), fmt.Sprint(raw...)
	}

	dump.Config(dump.WithoutColor(), dump.WithCallerSkip(l.WithCallerSkip))
	w := &bytes.Buffer{}
	dump.Std().Fprint(w, raw...)
	noCOlorWrappedString := w.String()

	if l.ColorfulStdout {
		fmt.Printf("!!!!!!!!!!!!!!!!%v", raw) 
		return noCOlorWrappedString, dump.Format(raw)  // << the error happens here
	}
	return noCOlorWrappedString, noCOlorWrappedString
}
func (kw *KafkaWorker) Listen() {
	kw.Logger.Println("KafkaWorker Starts Listening.")  // << the error happens here
	kw.isWorking = true
	//main blocking loop
workloop:
	for {
		//check if there is stop signal
		select {
		case <-*kw.NeedsToStop:
			break workloop
		default:
		}

		ev := kw.consumer.Poll(100)
		switch e := ev.(type) {
		case *kafka.Message:
			// application-specific processing
			kw.processMessage(e)
		case kafka.Error:
			kw.Logger.HandleError(e)
		default:
			// listening...
		}
	}
	kw.Logger.Println("KafkaWorker Stops Listening.")
} 
func (m *KafkaManager) InitManager() {
	for _, p := range profiles.Manager.All() {
		stopChanel := make(chan bool)
		kw := &KafkaWorker{
			Profile:     p,
			Logger:      log.CreateProductLogger(p.Name),
			NeedsToStop: &(stopChanel),
		}

		if err := kw.Init(); err == nil {
			m.Workers = append(m.Workers, kw)
			//increase the worker for an extra goroutine
			m.WG.Add(1)
			m.Routines = append(m.Routines, func() {
				kw.Listen() // << the error happens here
				//mark as done when one is finished
				m.WG.Done()
			})
		} else {
			kw.Logger.HandleError(err)
			m.Logger.Printf("[Abort] '%s' can't be initilized.\n", p.Name)
		}
	}
	m.Logger.Printf("All %d KafkaWorkers have been initialized.\n", len(m.Workers))
}

func (m *KafkaManager) ListenAll() {
	m.Logger.Printf("All %d KafkaWorkers Start Listening...\n", len(m.Workers))
	for _, r := range m.Routines {
		go r()
	}
	m.WG.Wait()
	m.Logger.Printf("All %d KafkaWorkers Stop Listening.\n", len(m.Workers))
}
tommynanny wrote this answer on 2023-02-08

@inhere after checking my call stack, it seems it is triggered by possible negative value of the times being negative from func RepeatChars[T byte | rune](char T, times int) []T at [email protected]/strutil/padding.go

from my particular case, the times becomes -2, probably needs to change

if times == 0 {
     return make([]T, 0)
}

into

if times <= 0 {
     return make([]T, 0)
}

goutil/strutil.RepeatBytes(char 32 = 0x20, times = -2)
goutil/strutil.RepeatBytes(char 32 = 0x20, times = -2)
goutil/dump.(*Dumper).advance(step = -1)

goutil/dump.(*Dumper).printRValue(d, t, v ,eleNum = 1, lenTip = "<gray>#len=1,cap=1</>", i = 0, sv)
//d
*github.com/gookit/goutil/dump.Dumper {Options: *github.com/gookit/goutil/dump.Options {Output: io.Writer(*bytes.Buffer) ..., NoType: false, NoColor: false, IndentLen: 2, IndentChar: 32, MaxDepth: 5, ShowFlag: 1, CallerSkip: 3, ColorTheme: github.com/gookit/goutil/dump.Theme [...], SkipNilField: false, SkipPrivate: false, BytesAsString: false}, mu: sync.RWMutex {w: (*sync.Mutex)(0x1400009a5a8), writerSem: 0, readerSem: 0, readerCount: -1073741824, readerWait: 0}, visited: map[github.com/gookit/goutil/dump.visit]int [], msValue: false, curDepth: 0, indentBytes: []uint8 len: 0, cap: 0, []}

//t
reflect.Type(*reflect.rtype) *{size: 24, ptrdata: 8, hash: 228187766, tflag: tflagExtraStar (2), align: 8, fieldAlign: 8, kind: 23, equal: nil, gcdata: *1, str: 62293, ptrToThis: 195648}

//v
reflect.Value {typ: *reflect.rtype {size: 24, ptrdata: 8, hash: 228187766, tflag: tflagExtraStar (2), align: 8, fieldAlign: 8, kind: 23, equal: nil, gcdata: *1, str: 62293, ptrToThis: 195648}, ptr: unsafe.Pointer(0x140003c2150), flag: 151}

//sv
reflect.Value {typ: *reflect.rtype {size: 16, ptrdata: 16, hash: 252279353, tflag: tflagExtraStar (2), align: 8, fieldAlign: 8, kind: 20, equal: runtime.nilinterequal, gcdata: *2, str: 49081, ptrToThis: 244160}, ptr: unsafe.Pointer(0x140001ca8b0), flag: 404}
inhere wrote this answer on 2023-02-09

@tommynanny Thank you very much!
I will fix it in the next version.

inhere wrote this answer on 2023-02-11
More Details About Repo
Owner Name gookit
Repo Name goutil
Full Name gookit/goutil
Language Go
Created Date 2018-07-03
Updated Date 2023-03-22
Star Count 1263
Watcher Count 29
Fork Count 142
Issue Count 3

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
What motion model is used? 1 2019-09-16 2023-02-11
[TECH] Integration tests: ping 1 2022-03-17 2023-02-04
Add build-info option to emit solc CompilerInput and CompilerOutput 0 2022-06-02 2023-03-10
Update div with many charts [remove it and his child components and re-create it] 1 2021-01-20 2023-02-16
ag-grid setPinnedTopRowData 3 2021-01-22 2023-02-19
relatablequery not working 0 2023-02-15 2023-02-22
Uncertain balance value 8 2022-10-17 2023-02-18
Most modifications not working 10 2022-11-15 2022-12-31
Support: What triggers the extension to connect to the cluster? 8 2021-06-10 2023-02-24
MariaDB set gtid_domain_id !=0, replication-manager 2.0 switchover question ? 5 2019-01-13 2023-03-15
Spec Merkle Mountain Ranges 1 2021-03-24 2023-01-18
PreserveStorage doesn't clean up ref counters, leading to unnecessary object copies 8 2022-03-12 2023-02-25
Pulse audio aun no funciona 8 2021-03-22 2023-03-17
Grafana Loki for SPOs page in Handbook 3 2022-05-14 2023-02-13
Series Images are Lost but Still Appear in Metadata Selection as Active 8 2022-05-10 2023-02-09
speed of gate bootstrapping 0 2022-02-06 2023-03-08
Crashing On Huawei Devices 2 2020-11-18 2023-02-15
Crash when using Example filter on Coder 1 2022-12-01 2023-02-01
File as clock / signal input 3 2021-07-09 2023-03-16
❌ 🐞 Bug Report : Bug in icon widget custom width (3.7 bug) 3 2022-09-14 2023-02-11
🐞 Bug Report: swiper-js Loading without a reason 1 2022-09-14 2023-02-11
🚧 🐞 Bug Report: Elementor not using the_content filter for whole page output 2 2022-09-14 2022-12-12
Supporting Json as a scalar type 2 2022-11-16 2023-02-20
Document Docker + NGINX HTTPS config 0 2022-02-28 2022-08-09
Derive: adding `visible_alias` attribute to complex subcommands results in duplicated aliases 5 2021-10-16 2023-03-03
[Bug] Inconsistency in naming it Dark mode or Night mode 0 2021-09-13 2023-02-19
Automatic destroy all charts on turbo:before-render causing issues 5 2022-03-14 2023-02-19
Problem on getting results 2 2021-11-03 2023-02-17
Protobuf version specification prevents Python 3.11 compatibility 1 2023-01-09 2023-02-17
Ability to more precisely configure load order 0 2022-06-27 2022-08-10
"default" task from included taskfile should be executed when no task name is provided 7 2022-01-23 2023-03-17
Bulk Rack Reservation Import not working (Unexpected column header "site" found.) 4 2022-12-06 2023-02-13
Being able to mark generated files with go:build tags 0 2023-01-01 2023-02-24
ImportError: cannot import name 'magic' from 'decompiler' (unknown location) 0 2022-07-25 2023-02-09
How to set a PublicAssociationMulti 2 2021-11-11 2023-02-18
ERROR: database file (db.tsv) not readable! on custom database 3 2021-04-28 2022-12-16
Invalid Repository url in Cargo.toml 0 2020-07-27 2023-02-19
themes route should include server id 1 2023-03-04 2023-03-16
Support types for `format_compact_decimal` (Babel 2.11.0) 3 2022-11-04 2023-03-08
Side for innstillinger og endre profil 0 2021-02-08 2023-02-04
Implement metadata & event model 0 2021-10-15 2022-08-15
The prediction results of ppyolo are all wrong when using mkldnn. 6 2021-09-14 2022-12-20
Brak zamówień zarówno w panelu allegro jak i po REST API 1 2022-12-20 2023-01-08
Margins of ListViewItem top Margin visibly changes if it ListViewItem shrinks or grows. 0 2023-02-21 2023-03-23
logPurchase event doesn't add price value to analytics 7 2022-09-01 2023-02-06
Timeline is supposed to be zoom-able 1 2021-10-25 2023-03-05
Append random suffix to global.name value to avoid collisions across client K8s clusters 0 2021-12-07 2023-02-18
What is the correct way to replace DLL built-in references (e.g. CoreModule.dll) in a csproj file with my own modified DLL? 11 2022-04-24 2023-03-14
Bubbles content don't appear 0 2016-09-16 2023-02-25
A11y tests for monitoring plugin 2 2022-02-01 2023-02-27