libct/intelrdt: simplify NewLastCmdError

For errors that only have a string and an underlying error, using
fmt.Errorf with %w to wrap an error is sufficient.

In this particular case, the code is simplified, and now we have
unwrappable errors as a bonus (same could be achieved by adding
(*LastCmdError).Unwrap() method, but that's adding more code).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-06-24 19:05:36 -07:00
parent e0ce428bce
commit 00d1562967
+2 -14
View File
@@ -759,22 +759,10 @@ func (raw *intelRdtData) join(id string) (string, error) {
return path, nil
}
type LastCmdError struct {
LastCmdStatus string
Err error
}
func (e *LastCmdError) Error() string {
return e.Err.Error() + ", last_cmd_status: " + e.LastCmdStatus
}
func NewLastCmdError(err error) error {
lastCmdStatus, err1 := getLastCmdStatus()
status, err1 := getLastCmdStatus()
if err1 == nil {
return &LastCmdError{
LastCmdStatus: lastCmdStatus,
Err: err,
}
return fmt.Errorf("%w, last_cmd_status: %s", err, status)
}
return err
}