From 9ec2a7c8ec3343ab1c659ad1473dc87a2854806b Mon Sep 17 00:00:00 2001 From: Yogesh Deshpande Date: Thu, 30 Jan 2025 18:23:53 +0000 Subject: [PATCH] Further work on logging index Signed-off-by: Yogesh Deshpande --- comid/tdx-profile/teetcbstatus.go | 8 ++++---- comid/tdx-profile/teetcbstatus_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/comid/tdx-profile/teetcbstatus.go b/comid/tdx-profile/teetcbstatus.go index 9815f0f..9b8f07a 100644 --- a/comid/tdx-profile/teetcbstatus.go +++ b/comid/tdx-profile/teetcbstatus.go @@ -26,12 +26,12 @@ func NewTeeTcbStatus(val []any) *TeeTcbStatus { } func (o *TeeTcbStatus) AddTeeTcbStatus(val []any) error { - for _, v := range val { + for i, v := range val { switch t := v.(type) { case string: *o = append(*o, t) default: - return fmt.Errorf("invalid type: %T for tcb status", t) + return fmt.Errorf("invalid type: %T for tcb status at index: %d", t, i) } } return nil @@ -42,12 +42,12 @@ func (o TeeTcbStatus) Valid() error { return fmt.Errorf("empty tcb status") } - for _, v := range o { + for i, v := range o { switch t := v.(type) { case string: continue default: - return fmt.Errorf("invalid type %T for tcb status", t) + return fmt.Errorf("invalid type: %T for tcb status at index: %d", t, i) } } return nil diff --git a/comid/tdx-profile/teetcbstatus_test.go b/comid/tdx-profile/teetcbstatus_test.go index 7b31cbf..4509764 100644 --- a/comid/tdx-profile/teetcbstatus_test.go +++ b/comid/tdx-profile/teetcbstatus_test.go @@ -44,7 +44,7 @@ func TestTcbStatus_AddTcbStatus_OK(t *testing.T) { } func TestTcbStatus_AddTcbStatus_NOK(t *testing.T) { - expectedErr := "invalid type: int for tcb status" + expectedErr := "invalid type: int for tcb status at index: 0" s := make([]any, len(TestInvalidTCBStatus)) for i := range TestInvalidTCBStatus { s[i] = TestInvalidTCBStatus[i] @@ -66,7 +66,7 @@ func TestTcbStatus_Valid_NOK(t *testing.T) { status := TeeTcbStatus{} err := status.Valid() assert.EqualError(t, err, expectedErr) - expectedErr = "invalid type int for tcb status" + expectedErr = "invalid type: int for tcb status at index: 0" s := make([]any, len(TestInvalidTCBStatus)) for i := range TestInvalidTCBStatus { s[i] = TestInvalidTCBStatus[i]