From 54183ba222bb28dc155e63d49be98d819993dbad Mon Sep 17 00:00:00 2001 From: Serge Bazanski Date: Fri, 1 Sep 2023 19:12:14 +0200 Subject: [PATCH] go/workspace: fix nix-instantiate exec error typecast Also skip nix tests on systems without nix. Change-Id: I4c0069a429df10a496b2651c2506b2d4625d5f43 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1585 Reviewed-by: q3k --- go/workspace/nix.go | 6 ++++-- go/workspace/nix_test.go | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go/workspace/nix.go b/go/workspace/nix.go index 8d005a7b..22b50cf4 100644 --- a/go/workspace/nix.go +++ b/go/workspace/nix.go @@ -48,8 +48,10 @@ func EvalHscloudNix(ctx context.Context, target any, path string) error { cmd := exec.CommandContext(ctx, "nix-instantiate", args...) out, err := cmd.Output() if err != nil { - eerr := err.(*exec.ExitError) - return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr) + if eerr, ok := err.(*exec.ExitError); ok { + return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr) + } + return fmt.Errorf("nix-instantiate failed: %w", err) } if err := json.Unmarshal(out, target); err != nil { diff --git a/go/workspace/nix_test.go b/go/workspace/nix_test.go index acb6d990..d1daf881 100644 --- a/go/workspace/nix_test.go +++ b/go/workspace/nix_test.go @@ -2,6 +2,7 @@ package workspace import ( "context" + "os" "testing" "github.com/google/go-cmp/cmp" @@ -49,6 +50,9 @@ func TestCheckNixPath(t *testing.T) { // TestEvalHscloud nix exercises EvalHscloudNix against // //go/workspace/exports.nix. func TestEvalHscloudNix(t *testing.T) { + if _, err := os.Stat("/nix/store"); err != nil { + t.Skip("no /nix/store") + } ctx, ctxC := context.WithCancel(context.Background()) defer ctxC()