Skip to content

Commit

Permalink
moved pipe & cmd cleanup to scanErr if block from defer func
Browse files Browse the repository at this point in the history
  • Loading branch information
dblinkhorn committed Jan 3, 2025
1 parent e5433bc commit 2701aec
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions actions/trigger-argo-workflow/cmd/trigger-argo-workflow/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,16 @@ func (a App) runCmd(md GitHubActionsMetadata) (string, string, error) {
return "", "", fmt.Errorf("failed to start command: %w", err)
}

waitCalled := false
pipeClosed := false

defer func() {
if !pipeClosed {
_ = stdoutPipe.Close()
}
if !waitCalled {
_ = cmd.Wait()
}
}()

uri, out, scanErr := a.outputWithURI(stdoutPipe)
if scanErr != nil {
_ = stdoutPipe.Close()
_ = cmd.Wait()
return uri, out, scanErr
}

if err := cmd.Wait(); err != nil {
return uri, out, fmt.Errorf("command failed: %w", err)
}
waitCalled = true

return uri, out, nil
}
Expand Down

0 comments on commit 2701aec

Please sign in to comment.