gpg: fix error handling during decryption

An non-zero exit code from the execution of gpg during decryption would
prevent aerc from parsing the output of gpg. The output should always be
parsed. Gpg can exit with an error due to not being able to validate a
signature. Aerc handles this error with the UI, and therefore all output
should be parsed regardless of exit state of gpg. The parsing of stdout
will find the errors and report back to aerc properly.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
This commit is contained in:
Tim Culverhouse 2022-06-27 07:31:31 -05:00 committed by Robin Jarry
parent 506f8f165c
commit ccd76e6494
1 changed files with 5 additions and 3 deletions

View File

@ -18,7 +18,11 @@ func Decrypt(r io.Reader) (*models.MessageDetails, error) {
}
args := []string{"--decrypt"}
g := newGpg(bytes.NewReader(orig), args)
err = g.cmd.Run()
_ = g.cmd.Run()
outRdr := bytes.NewReader(g.stdout.Bytes())
// Always parse stdout, even if there was an error running command.
// We'll find the error in the parsing
err = parse(outRdr, md)
if err != nil {
err = parseError(g.stderr.String())
switch GPGErrors[err.Error()] {
@ -29,7 +33,5 @@ func Decrypt(r io.Reader) (*models.MessageDetails, error) {
return nil, err
}
}
outRdr := bytes.NewReader(g.stdout.Bytes())
parse(outRdr, md)
return md, nil
}