mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user