internal: don't panic on all/all
If CompareBuildContexts sees all/all, it prefers it instead of
panicking.
Change-Id: I50ff46fa2bbad47cfe5539297a08744dd62b261c
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/305969
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/build_context.go b/internal/build_context.go
index 2e2471c..823c547 100644
--- a/internal/build_context.go
+++ b/internal/build_context.go
@@ -46,11 +46,17 @@
if c1 == c2 {
return 0
}
- // We should never see a BuildContext with "all" here.
- if c1.GOOS == All || c1.GOARCH == All || c2.GOOS == All || c2.GOARCH == All {
- panic("BuildContext with 'all'")
+ // Although we really shouldn't see a BuildContext with "all" here, we may if the
+ // DB erroneously has both an all/all row and some other row. So just prefer the all/all.
+ if c1 == BuildContextAll {
+ if c2 == BuildContextAll {
+ return 0
+ }
+ return -1
}
-
+ if c2 == BuildContextAll {
+ return 1
+ }
pos := func(c BuildContext) int {
for i, d := range BuildContexts {
if c == d {