Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 (chore): use 'errors.As' and wrap exec errors in repository.go #4730

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/plugins/golang/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package golang

import (
"encoding/json"
"errors"
"fmt"
"os"
"os/exec"
Expand All @@ -39,7 +40,8 @@ func findGoModulePath() (string, error) {
cmd.Env = append(cmd.Env, os.Environ()...)
out, err := cmd.Output()
if err != nil {
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not use errors.Is() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check that out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errors.Is just checks the error and does not populate it to exitErr.

err = fmt.Errorf("%s", string(exitErr.Stderr))
}
return "", err
Expand Down Expand Up @@ -77,7 +79,8 @@ func FindCurrentRepo() (string, error) {
cmd := exec.Command("go", "mod", "init")
cmd.Env = append(cmd.Env, os.Environ()...)
if _, err := cmd.Output(); err != nil {
if exitErr, isExitErr := err.(*exec.ExitError); isExitErr {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
err = fmt.Errorf("%s", string(exitErr.Stderr))
}
// give up, let the user figure it out
Expand Down
Loading