show verbose output from go mod tidy for debugging

This commit is contained in:
Jeff Carr 2024-12-17 23:58:43 -06:00
parent ea14fc629d
commit 063e4e57c8
2 changed files with 39 additions and 1 deletions

View File

@ -41,7 +41,7 @@ func redoGoMod(repo *gitpb.Repo) error {
log.Warn("go mod init failed", err)
return err
}
if err := repo.StrictRun([]string{"go", "mod", "tidy", "-go=1.21"}); err != nil {
if err := runVerbose(repo.FullPath, []string{"go", "mod", "tidy", "-go=1.21"}); err != nil {
log.Warn("go mod tidy failed", err)
return err
}

38
run.go
View File

@ -68,3 +68,41 @@ func runStrict(wd string, cmd []string) {
log.Info(i, line)
}
}
func runVerbose(wd string, cmd []string) error {
var err error
log.DaemonMode(true)
defer log.DaemonMode(false)
if wd != "" {
if err = os.Chdir(wd); err != nil {
return fmt.Errorf("cd %s failed %v", wd, err)
}
}
log.Info(wd, "running:", wd, cmd)
// result := shell.Run(cmd)
result := shell.Run(cmd)
if result.Error != nil {
log.Info("cmd failed", wd, cmd, err)
for _, line := range result.Stdout {
log.Info(line)
}
for i, line := range result.Stderr {
log.Info("STDERR:", i, line)
}
return result.Error
}
if result.Exit != 0 {
log.Info("cmd failed", wd, cmd, err)
for _, line := range result.Stdout {
log.Info(line)
}
for i, line := range result.Stderr {
log.Info("STDERR:", i, line)
}
return fmt.Errorf("cmd failed with %d", result.Exit)
}
for _, line := range result.Stdout {
log.Info(line)
}
return nil
}