Skip to content

Commit a3d6132

Browse files
authored
nix: fix PkgExists panic for some missing packages (#249)
1 parent adda549 commit a3d6132

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

nix/nix.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func parseInfo(pkg string, data []byte) *Info {
5959
if err != nil {
6060
panic(err)
6161
}
62-
if len(results) != 1 {
63-
panic(fmt.Sprintf("unexpected number of results: %d", len(results)))
64-
}
6562
for _, result := range results {
6663
pkgInfo := &Info{
6764
NixName: pkg,

nix/nix_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package nix
2+
3+
import "testing"
4+
5+
func TestPkgExists(t *testing.T) {
6+
// nix-env returns an empty JSON object instead of an error for some
7+
// missing packages, which was leading to a panic. "rust" happens to be
8+
// one of those packages.
9+
pkg := "rust"
10+
exists := PkgExists(pkg)
11+
if exists {
12+
t.Errorf("got PkgExists(%q) = true, want false.", pkg)
13+
}
14+
}

0 commit comments

Comments
 (0)