From 561ffd9c866664297d8089ab1ab76ff690e91d17 Mon Sep 17 00:00:00 2001 From: Alex Bezzubov Date: Fri, 22 Sep 2023 13:16:20 +0200 Subject: [PATCH] test: usability in err msg on linguist clone --- internal/tests/utils.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/tests/utils.go b/internal/tests/utils.go index 0e2b411..9110b0b 100644 --- a/internal/tests/utils.go +++ b/internal/tests/utils.go @@ -17,13 +17,13 @@ func MaybeCloneLinguist(envVar, url, commit string) (string, bool, error) { if !isLinguistCloned { linguistTmpDir, err = ioutil.TempDir("", "linguist-") if err != nil { - return "", false, err + panic(err) } isCleanupNeeded = true cmd := exec.Command("git", "clone", "--depth", "150", url, linguistTmpDir) if err := cmd.Run(); err != nil { - panic(fmt.Errorf("%s: %w", cmd.String(), err)) + panicOn(cmd.String(), err) } } @@ -38,11 +38,15 @@ func MaybeCloneLinguist(envVar, url, commit string) (string, bool, error) { cmd := exec.Command("git", "checkout", commit) if err := cmd.Run(); err != nil { - panic(fmt.Errorf("%s: %w", cmd.String(), err)) + panicOn(cmd.String(), err) } if err = os.Chdir(cwd); err != nil { - panic(fmt.Errorf("%s: %w", cmd.String(), err)) + panicOn(cmd.String(), err) } return linguistTmpDir, isCleanupNeeded, nil } + +func panicOn(cmd string, err error) { + panic(fmt.Errorf("%q returned %w", cmd, err)) +}