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