contrib: implements tool prints stderr if castxml fails

Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
Sven Anderson 2021-10-04 18:53:43 +09:00 committed by mergify[bot]
parent 3210885d21
commit 97630486ee
1 changed files with 7 additions and 13 deletions

View File

@ -2,6 +2,7 @@ package implements
import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"os"
@ -89,23 +90,16 @@ func parseCFunctionsFromCmd(args []string) (CFunctions, error) {
cmd := exec.Command(args[0], args[1:]...)
logger.Printf("will call: %v", cmd)
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
err = cmd.Start()
if err != nil {
return nil, err
}
xdec := xml.NewDecoder(stdout)
parseErr := xdec.Decode(&cf)
err = cmd.Wait()
stdout, err := cmd.Output()
if err != nil {
var ee *exec.ExitError
if errors.As(err, &ee) {
err = fmt.Errorf("%w, stderr:\n%s", err, ee.Stderr)
}
return nil, err
}
parseErr := xml.Unmarshal(stdout, &cf)
if parseErr != nil {
return nil, parseErr
}