Skip to content

Commit

Permalink
Only log an error if Spack actually fails
Browse files Browse the repository at this point in the history
Running this:

$ spack buildcache update-index ./aksdjhfajksdf/
==> Warning: Encountered problem listing packages at file:///nfs/hgi/ah37/aksdjhfajksdf/build_cache: [Errno 2] No such file or directory: '/nfs/hgi/ah37/aksdjhfajksdf/build_cache'
==> Error: Unable to generate package index, Failed to get list of specs from file:///nfs/hgi/ah37/aksdjhfajksdf/build_cache

exits zero! Thanks Spack!
  • Loading branch information
sersorrel committed Feb 6, 2024
1 parent 7d25faf commit 52d84ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions reindex/reindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package reindex
import (
"log/slog"
"os/exec"
"strings"
"time"

"github.com/wtsi-hgi/go-softpack-builder/config"
Expand All @@ -49,14 +50,20 @@ type Scheduler struct {
func NewScheduler(conf *config.Config, builder Builder) *Scheduler {
reindex := func() {
cmd := exec.Command("spack", "buildcache", "update-index", "--", conf.S3.BinaryCache) //nolint:gosec

out, err := cmd.CombinedOutput()

var outstr, errstr string

if out != nil {
outstr = string(out)
}

if err != nil {
slog.Error("could not run spack buildcache update-index", "err", err.Error())
errstr = err.Error()
}

if len(out) > 0 {
slog.Error("spack reindex failed", "out", string(out))
if err != nil || strings.Contains(outstr, "Error") {
slog.Error("spack reindex failed", "err", errstr, "out", outstr)
}
}

Expand Down
2 changes: 1 addition & 1 deletion reindex/reindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestReindex(t *testing.T) {
started := fb.buildCalled()

getIndex(cacheDir, started)
So(logWriter.String(), ShouldContainSubstring, `level=ERROR msg="could not run spack buildcache update-index"`)
So(logWriter.String(), ShouldContainSubstring, `level=ERROR msg="spack reindex failed"`)
So(logWriter.String(), ShouldContainSubstring, "executable file not found in $PATH")
})
})
Expand Down

0 comments on commit 52d84ee

Please sign in to comment.