algolia / cli

🔍 Algolia’s official CLI devtool
https://www.algolia.com/doc/tools/cli
MIT License
101 stars 26 forks source link

Deleting virtual replica panics #166

Open kai687 opened 1 week ago

kai687 commented 1 week ago

Deleting a standard replica index works, but trying to delete a virtual replica causes a panic:

Deleting replica index test_replica ⣾panic: runtime error: slice bounds out of range [:-1]

goroutine 1 [running]:
github.com/algolia/cli/pkg/cmd/indices/delete.detachReplicaIndex({0x16f516fd5, 0xc}, {0x14000452520, 0xa}, 0x1400042a300)
    /home/runner/work/cli/cli/pkg/cmd/indices/delete/delete.go:222 +0x484
github.com/algolia/cli/pkg/cmd/indices/delete.deleteReplicaIndex(0x140001724d0?, 0x1400030ba80)
    /home/runner/work/cli/cli/pkg/cmd/indices/delete/delete.go:179 +0xd4
github.com/algolia/cli/pkg/cmd/indices/delete.runDeleteCmd(0x1400012b2c0)
    /home/runner/work/cli/cli/pkg/cmd/indices/delete/delete.go:155 +0x884
github.com/algolia/cli/pkg/cmd/indices/delete.NewDeleteCmd.func1(0x14000217680?, {0x140002ccfb0?, 0x1?, 0x1?})
    /home/runner/work/cli/cli/pkg/cmd/indices/delete/delete.go:78 +0xa4
github.com/spf13/cobra.(*Command).execute(0x14000217680, {0x140002ccf90, 0x1, 0x1})
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:872 +0x4d0
github.com/spf13/cobra.(*Command).ExecuteC(0x140001d9b80)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:990 +0x354
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.5.0/command.go:927
github.com/algolia/cli/pkg/cmd/root.Execute()
    /home/runner/work/cli/cli/pkg/cmd/root/root.go:198 +0x2e4
main.main()
    /home/runner/work/cli/cli/cmd/algolia/main.go:10 +0x1c
kai687 commented 1 week ago

I guess because we're looking for the replica name in the settings, but the name is actually (virtual(replicaName)).

kai687 commented 1 week ago

Of course, deleting an index with a virtual replica index fails as well, as we try to look for an index "virtual(replicaName)", but the name is actually still "replicaName".