Skip to content

bar.Finish() cause panic: runtime error: index out of range [-1] #212

@baylesa-dev

Description

@baylesa-dev

In my project, running bar.Finish() cause runtime error: index out of range [-1]. Any idea why ? 😬

goroutine 1 [running]:
github.com/schollz/progressbar/v3.(*ProgressBar).render(0xc0012d5688)
        /app/go/pkg/mod/github.com/schollz/progressbar/v3@v3.18.0/progressbar.go:942 +0x606
github.com/schollz/progressbar/v3.(*ProgressBar).Add64(0xc0012d5688, 0x0)
        /app/go/pkg/mod/github.com/schollz/progressbar/v3@v3.18.0/progressbar.go:729 +0x487
github.com/schollz/progressbar/v3.(*ProgressBar).Add(...)
        /app/go/pkg/mod/github.com/schollz/progressbar/v3@v3.18.0/progressbar.go:655
github.com/schollz/progressbar/v3.(*ProgressBar).Finish(0xc0012d5688)
        /app/go/pkg/mod/github.com/schollz/progressbar/v3@v3.18.0/progressbar.go:638 +0xa5
gitlab.com/baylesa/health-map-db/internal/importer/services.ImportAnnuaireSante(0xc00110fbc0, 0xc000c48b60, {0x62af8a0, 0xc000c27890})
        /app/Developer/health-map-db/internal/importer/services/import.go:88 +0x5ba
main.CreateCliCmd.func1({0x62af8a0, 0xc000c27890}, 0xc000c27890?)
        /app/Developer/health-map-db/cmd/importer/main.go:51 +0xe5
github.com/urfave/cli/v3.(*Command).Run(0xc000c06788, {0x62af8a0, 0xc000c27890}, {0xc000e1a0e0, 0x7, 0x7})
        /app/go/pkg/mod/github.com/urfave/cli/v3@v3.0.0-beta1/command.go:645 +0x1957
github.com/urfave/cli/v3.(*Command).Run(0xc000c06508, {0x62af8a0, 0xc000c27560}, {0xc000146000, 0x8, 0x8})
        /app/go/pkg/mod/github.com/urfave/cli/v3@v3.0.0-beta1/command.go:618 +0x18f4
main.main()
        /app/Developer/health-map-db/cmd/importer/main.go:25 +0x191
func main() {
	total := getTotal()
	bar := progressbar.NewOptions64(total,
		progressbar.OptionSetDescription("🤖 Importing practitioners"),
		progressbar.OptionSetWriter(os.Stderr),
		progressbar.OptionSetWidth(10),
		progressbar.OptionShowTotalBytes(false),
		progressbar.OptionFullWidth(),
		progressbar.OptionThrottle(65*time.Millisecond),
		progressbar.OptionShowCount(),
		progressbar.OptionSetMaxDetailRow(10),
		progressbar.OptionSpinnerType(14),
		progressbar.OptionOnCompletion(func() {
			fmt.Fprint(os.Stderr, "\n")
		}),
		progressbar.OptionSetRenderBlankState(true),
	)

	batchSize := 100

	for _, url := range urls {
		_ = bar.Add(batchSize)
	}

	_ = bar.Finish()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions