bazel-gazelle
bazel-gazelle copied to clipboard
panic while running gazelle update-repos with prune
What version of gazelle are you using?
0.25
What version of rules_go are you using?
0.32.0
What version of Bazel are you using?
Bazelisk version: v1.11.0 Build label: 5.1.1 Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Fri Apr 8 15:49:48 2022 (1649432988) Build timestamp: 1649432988 Build timestamp as int: 1649432988
Does this issue reproduce with the latest releases of all the above?
I believe I am on the latest releases
What operating system and processor architecture are you using?
linux/amd64
What did you do?
I ran a rule which should run gazelle update-repos
which looks like this:
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=go_deps.bzl%go_dependencies",
"-prune",
],
command = "update-repos",
)
What did you expect to see?
Bazel should have updated go depedencies and exited successfully
What did you see instead?
Bazel panics with the following:
panic: runtime error: index out of range [4] with length 1
goroutine 1 [running]:
github.com/bazelbuild/bazel-gazelle/rule.byName.Swap(...)
external/bazel_gazelle/rule/rule.go:510
sort.insertionSort({0x4d4b988, 0xc00019ff80}, 0x0, 0x12)
GOROOT/src/sort/sort.go:41 +0x64
sort.stable({0x4d4b988, 0xc00019ff80}, 0x12)
GOROOT/src/sort/sort.go:390 +0x70
sort.Stable({0x4d4b988, 0xc00019ff80})
GOROOT/src/sort/sort.go:379 +0x39
github.com/bazelbuild/bazel-gazelle/rule.(*File).SortMacro(0xc0002a28c0)
external/bazel_gazelle/rule/rule.go:399 +0xb4
main.updateRepos({0xc00003001a, 0x1a}, {0xc000128020, 0x3, 0x3})
external/bazel_gazelle/cmd/gazelle/update-repos.go:293 +0x1fc9
main.run({0xc00003001a?, 0x1a?}, {0xc000128010?, 0x4?, 0x4?})
external/bazel_gazelle/cmd/gazelle/gazelle.go:99 +0x1d8
main.main()
external/bazel_gazelle/cmd/gazelle/gazelle.go:72 +0xdd
I noticed that if I remove -prune
gazelle works correctly. Seems like a bug? I'm new to both Bazel and Gazelle, so this could be user error but as there is a panic here I suspect that at a minimum some bounds checking is missing here.