Skip to content

Commit

Permalink
feat: polish offline rauc err msg (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH authored Dec 17, 2024
1 parent 6baec1f commit a92422b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions service/rauc.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,22 @@ func MockRAUCInfo(content string) (string, error) {
func GetRAUCInfo(path string) (string, error) {
cmd := exec.Command("rauc", "info", path)
var out bytes.Buffer
var errReason bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &errReason
err := cmd.Run()

if err != nil {
logger.Error("get info from rauc fail", zap.Error(err))
logger.Error("get info from rauc fail", zap.Error(err), zap.String("reason", errReason.String()), zap.String("path", path))
lines := strings.Split(errReason.String(), "\n")
if len(lines) < 2 {
return "", fmt.Errorf("get info from rauc fail: %s", errReason.String())
}
theLastTwoLine := lines[len(lines)-2]
return "", fmt.Errorf("get info from rauc fail: %s", theLastTwoLine)
}

return out.String(), err
return out.String(), nil
}

func GetDescription(raucInfo string) (string, error) {
Expand Down

0 comments on commit a92422b

Please # to comment.