From 00d156296718500f8c307e3dcb77cb37dd8e9ed2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 24 Jun 2021 19:05:36 -0700 Subject: [PATCH] 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 --- libcontainer/intelrdt/intelrdt.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/libcontainer/intelrdt/intelrdt.go b/libcontainer/intelrdt/intelrdt.go index 8900983c9..3b61a70c3 100644 --- a/libcontainer/intelrdt/intelrdt.go +++ b/libcontainer/intelrdt/intelrdt.go @@ -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 }