Skip to content

Commit

Permalink
Ensure to give back stderr when GPG failed
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed Dec 28, 2020
1 parent cc6ca28 commit 06d10e8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crypto/gpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crypto
import (
"bytes"
"context"
"fmt"
"io"
"os/exec"
)
Expand Down Expand Up @@ -34,7 +35,13 @@ func (g *gpg) DecryptWithRecipient(ctx context.Context, encrypted []byte, userID
}

func (g *gpg) runGPGCommand(ctx context.Context, stdin io.Reader, args ...string) ([]byte, error) {
var stdout, stderr bytes.Buffer
cmd := exec.CommandContext(ctx, g.executable, args...)
cmd.Stdin = stdin
return cmd.Output()
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("failed to run GPG: stderr: %s: err: %w", stderr.String(), err)
}
return stdout.Bytes(), nil
}

0 comments on commit 06d10e8

Please sign in to comment.