Skip to content

Commit 646d2b5

Browse files
committed
🌱 (chore): use errors.As and wrap exec errors in repository.go
Refactored error handling in `repository.go`: - Replaced type assertion with `errors.As` for `*exec.ExitError` - Ensured command stderr is preserved in the wrapped `fmt.Errorf` output - Set up for better error introspection and debugging
1 parent 6452e9f commit 646d2b5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/plugins/golang/repository.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package golang
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"fmt"
2223
"os"
2324
"os/exec"
@@ -39,7 +40,8 @@ func findGoModulePath() (string, error) {
3940
cmd.Env = append(cmd.Env, os.Environ()...)
4041
out, err := cmd.Output()
4142
if err != nil {
42-
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
43+
var exitErr *exec.ExitError
44+
if errors.As(err, &exitErr) {
4345
err = fmt.Errorf("%s", string(exitErr.Stderr))
4446
}
4547
return "", err
@@ -77,7 +79,8 @@ func FindCurrentRepo() (string, error) {
7779
cmd := exec.Command("go", "mod", "init")
7880
cmd.Env = append(cmd.Env, os.Environ()...)
7981
if _, err := cmd.Output(); err != nil {
80-
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
82+
var exitErr *exec.ExitError
83+
if errors.As(err, &exitErr) {
8184
err = fmt.Errorf("%s", string(exitErr.Stderr))
8285
}
8386
// give up, let the user figure it out

0 commit comments

Comments
 (0)