Skip to content

Commit 944a110

Browse files
committed
Better recording of errors from plugins
1 parent 81a6825 commit 944a110

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

plugin/plugin.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package plugin
2121
import (
2222
"bytes"
2323
"context"
24+
"errors"
2425
"fmt"
2526
"io"
2627
"strings"
@@ -101,11 +102,9 @@ func (uploader *FwUploader) GetFirmwareVersion(portAddress string, stdout, stder
101102
if stderr != nil {
102103
proc.RedirectStderrTo(stderr)
103104
}
104-
if err := proc.RunWithinContext(context.Background()); err != nil {
105-
return nil, err
106-
}
107-
res := &GetFirmwareVersionResult{}
105+
pluginExecErr := proc.RunWithinContext(context.Background())
108106

107+
res := &GetFirmwareVersionResult{}
109108
fwVersionPrefix := "FIRMWARE-VERSION: "
110109
fwErrorPrefix := "GET-VERSION-ERROR: "
111110
for _, line := range strings.Split(buffer.String(), "\n") {
@@ -117,7 +116,14 @@ func (uploader *FwUploader) GetFirmwareVersion(portAddress string, stdout, stder
117116
res.Error = strings.TrimPrefix(line, fwErrorPrefix)
118117
}
119118
}
120-
return res, nil
119+
if res.Error != "" {
120+
if pluginExecErr != nil {
121+
err = fmt.Errorf("%s: %w", res.Error, pluginExecErr)
122+
} else {
123+
err = errors.New(res.Error)
124+
}
125+
}
126+
return res, err
121127
}
122128

123129
// GetFirmwareVersionResult contains the result of GetFirmwareVersion command

0 commit comments

Comments
 (0)