Skip to content

Commit

Permalink
fix: improved error messages for common problems with the script
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Jun 6, 2021
1 parent c092d21 commit de9e525
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ func run(cmd *cobra.Command, args []string) error {
}
executablePath, err := exec.LookPath(parsedCommand[0])
if err != nil {
return fmt.Errorf("could not find executable %s", parsedCommand[0])
if _, err := os.Stat(parsedCommand[0]); os.IsNotExist(err) {
return fmt.Errorf("could not find executable %s", parsedCommand[0])
}
return fmt.Errorf("could not find executable %s, does it have executable privileges?", parsedCommand[0])
}
// Executable needs to be defined with an absolute path since it will be run within the context of repositories
if !filepath.IsAbs(executablePath) {
Expand Down
2 changes: 1 addition & 1 deletion internal/multigitter/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r Printer) runSingleRepo(ctx context.Context, repo domain.Repository) erro

err = cmd.Run()
if err != nil {
return err
return transformExecError(err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/multigitter/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (r Runner) runSingleRepo(ctx context.Context, repo domain.Repository) (doma

err = cmd.Run()
if err != nil {
return nil, err
return nil, transformExecError(err)
}

if changed, err := sourceController.Changes(); err != nil {
Expand Down
16 changes: 16 additions & 0 deletions internal/multigitter/shared.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package multigitter

import (
"syscall"

"github.com/pkg/errors"
)

type urler interface {
URL() string
}

func transformExecError(err error) error {
var sysErr syscall.Errno
if ok := errors.As(err, &sysErr); ok {
if sysErr.Error() == "exec format error" {
return errors.New("the script or program is in the wrong format")
}
}
return err
}

0 comments on commit de9e525

Please sign in to comment.