From cc0883ca168f39e0fc2767900ae636482df5c2bb Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Wed, 11 Oct 2023 20:21:09 +0000 Subject: [PATCH 01/11] Add logging and recover from panic --- sonic_data_client/db_client.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 3b73b50f..96c0941d 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -721,6 +721,12 @@ func makeJSON_redis(msi *map[string]interface{}, key *string, op *string, mfv ma // emitJSON marshalls map[string]interface{} to JSON byte stream. func emitJSON(v *map[string]interface{}) ([]byte, error) { //j, err := json.MarshalIndent(*v, "", indentString) + defer func() { + if r := recover(); r != nil { + log.V(2).Infof("Recovered from panic", r) + log.V(2).Infof("Current state of map to be serialized is: ", *v) + } + } j, err := json.Marshal(*v) if err != nil { return nil, fmt.Errorf("JSON marshalling error: %v", err) @@ -759,9 +765,13 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] dbkeys = []string{tblPath.tableName + tblPath.delimitor + tblPath.tableKey} } + log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) + log.V(4).Infof("State of map before adding redis data %v", msi) + // Asked to use jsonField and jsonTableKey in the final json value if tblPath.jsonField != "" && tblPath.jsonTableKey != "" { val, err := redisDb.HGet(dbkeys[0], tblPath.field).Result() + log.V(4).Infof("Data pulled for key %s and field %s: %s", dbkeys[0], tblPath.field, val) if err != nil { log.V(3).Infof("redis HGet failed for %v %v", tblPath, err) // ignore non-existing field which was derived from virtual path @@ -779,7 +789,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] log.V(2).Infof("redis HGetAll failed for %v, dbkey %s", tblPath, dbkey) return err } - + log.V(4).Infof("Data pulled for dbkey %s: %v", dbkey, fv) if tblPath.jsonTableKey != "" { // If jsonTableKey was prepared, use it err = makeJSON_redis(msi, &tblPath.jsonTableKey, op, fv) } else if (tblPath.tableKey != "" && !useKey) || tblPath.tableName == dbkey { @@ -800,6 +810,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] } log.V(6).Infof("Added idex %v fv %v ", idx, fv) } + log.V(4).Infof("State of map after adding redis data %v", *msi) return nil } @@ -839,6 +850,7 @@ func tableData2TypedValue(tblPaths []tablePath, op *string) (*gnmipb.TypedValue, log.V(2).Infof("redis HGet failed for %v", tblPath) return nil, err } + log.V(4).Infof("Data pulled for key %s and field %s: %s", key, tblPath.field, val) // TODO: support multiple table paths return &gnmipb.TypedValue{ Value: &gnmipb.TypedValue_StringVal{ From ae2b649f01b838660f2349786262c9fb63c1c3f8 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Wed, 11 Oct 2023 22:05:21 +0000 Subject: [PATCH 02/11] Drop sending data if panic happens --- sonic_data_client/db_client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 96c0941d..935a318e 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -311,6 +311,7 @@ func (c *DbClient) PollRun(q *queue.PriorityQueue, poll chan struct{}, w *sync.W for gnmiPath, tblPaths := range c.pathG2S { val, err := tableData2TypedValue(tblPaths, nil) if err != nil { + log.V(2).Infof("Unable to create gnmi TypedValue due to err: %v", err) return } @@ -820,6 +821,9 @@ func msi2TypedValue(msi map[string]interface{}) (*gnmipb.TypedValue, error) { log.V(2).Infof("emitJSON err %s for %v", err, msi) return nil, fmt.Errorf("emitJSON err %s for %v", err, msi) } + if jv == nil { // json is nil because of potential panic happen + return nil, fmt.Errorf("emitJSON failed due to panic") + } return &gnmipb.TypedValue{ Value: &gnmipb.TypedValue_JsonIetfVal{ JsonIetfVal: jv, @@ -858,7 +862,6 @@ func tableData2TypedValue(tblPaths []tablePath, op *string) (*gnmipb.TypedValue, }}, nil } } - err := TableData2Msi(&tblPath, useKey, nil, &msi) if err != nil { return nil, err From f030ad4aa3ea1735f05a8fa34c23e0d6e2d61167 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Wed, 11 Oct 2023 22:38:48 +0000 Subject: [PATCH 03/11] Call defer function --- sonic_data_client/db_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 935a318e..355e48c5 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -727,7 +727,7 @@ func emitJSON(v *map[string]interface{}) ([]byte, error) { log.V(2).Infof("Recovered from panic", r) log.V(2).Infof("Current state of map to be serialized is: ", *v) } - } + }() j, err := json.Marshal(*v) if err != nil { return nil, fmt.Errorf("JSON marshalling error: %v", err) From 43b08353e44c64282a02d6403853af3805e3a625 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Wed, 11 Oct 2023 23:33:37 +0000 Subject: [PATCH 04/11] Add UT --- gnmi_server/server_test.go | 79 +++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index eb3a5d4f..ff09a5c5 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -3713,6 +3713,83 @@ func TestTableData2MsiUseKey(t *testing.T) { } } +func TestRecoverFromJSONSerializationPanic(t *testing.T) { + panicMarshal := func(v interface{}) ([]byte, error) { + panic("json.Marshal panics and is unable to serialize JSON") + } + mock := gomonkey.ApplyFunc(json.Marshal, panicMarshal) + defer mock.Reset() + + s := createServer(t, 8081) + go runServer(t, s) + defer s.s.Stop() + + tests := []struct { + desc string + q client.Query + want []client.Notification + poll int + }{ + { + desc: "poll query COUNTERS/Ethernet*", + poll: 10, + q: client.Query{ + Target: "COUNTERS_DB", + Type: client.Poll, + Queries: []client.Path{{"COUNTERS", "Ethernet*"}}, + TLS: &tls.Config{InsecureSkipVerify: true}, + }, + want: []client.Notification{ + client.Connected{}, + client.Sync{}, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.desc, func(t *testing.T) { + q := tt.q + q.Addrs = []string{"127.0.0.1:8081"} + c := client.New() + var gotNoti []client.Notification + q.NotificationHandler = func(n client.Notification) error { + if nn, ok := n.(client.Update); ok { + nn.TS = time.Unix(0, 200) + gotNoti = append(gotNoti, nn) + } else { + gotNoti = append(gotNoti, n) + } + return nil + } + + wg := new(sync.WaitGroup) + wg.Add(1) + + go func() { + defer wg.Done() + if err := c.Subscribe(context.Background(), q); err != nil { + t.Errorf("c.Subscribe(): got error %v, expected nil", err) + } + }() + + wg.Wait() + + for i := 0; i < tt.poll; i++ { + if err := c.Poll(); err != nil { + t.Errorf("c.Poll(): got error %v, expected nil", err) + } + } + + if len(gotNoti) == 0 { + t.Errorf("expected non zero notifications") + } + + c.Close() + }) + } + +} + func TestGnmiSetBatch(t *testing.T) { mockCode := ` @@ -4087,4 +4164,4 @@ func init() { // Inform gNMI server to use redis tcp localhost connection sdc.UseRedisLocalTcpPort = true -} \ No newline at end of file +} From 50cc3146fda9bd92e3fc7bcb4c95d6df7ba7118e Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Thu, 12 Oct 2023 20:08:48 +0000 Subject: [PATCH 05/11] Adjust test --- gnmi_server/server_test.go | 5 +++-- sonic_data_client/db_client.go | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index ff09a5c5..0bc8d519 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -3717,8 +3717,6 @@ func TestRecoverFromJSONSerializationPanic(t *testing.T) { panicMarshal := func(v interface{}) ([]byte, error) { panic("json.Marshal panics and is unable to serialize JSON") } - mock := gomonkey.ApplyFunc(json.Marshal, panicMarshal) - defer mock.Reset() s := createServer(t, 8081) go runServer(t, s) @@ -3774,6 +3772,9 @@ func TestRecoverFromJSONSerializationPanic(t *testing.T) { wg.Wait() + mock := gomonkey.ApplyFunc(json.Marshal, panicMarshal) + defer mock.Reset() + for i := 0; i < tt.poll; i++ { if err := c.Poll(); err != nil { t.Errorf("c.Poll(): got error %v, expected nil", err) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 355e48c5..c2a68c71 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -725,7 +725,7 @@ func emitJSON(v *map[string]interface{}) ([]byte, error) { defer func() { if r := recover(); r != nil { log.V(2).Infof("Recovered from panic", r) - log.V(2).Infof("Current state of map to be serialized is: ", *v) + //log.V(2).Infof("Current state of map to be serialized is: ", *v) } }() j, err := json.Marshal(*v) @@ -766,13 +766,13 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] dbkeys = []string{tblPath.tableName + tblPath.delimitor + tblPath.tableKey} } - log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) - log.V(4).Infof("State of map before adding redis data %v", msi) + //log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) + //log.V(4).Infof("State of map before adding redis data %v", msi) // Asked to use jsonField and jsonTableKey in the final json value if tblPath.jsonField != "" && tblPath.jsonTableKey != "" { val, err := redisDb.HGet(dbkeys[0], tblPath.field).Result() - log.V(4).Infof("Data pulled for key %s and field %s: %s", dbkeys[0], tblPath.field, val) + //log.V(4).Infof("Data pulled for key %s and field %s: %s", dbkeys[0], tblPath.field, val) if err != nil { log.V(3).Infof("redis HGet failed for %v %v", tblPath, err) // ignore non-existing field which was derived from virtual path @@ -790,7 +790,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] log.V(2).Infof("redis HGetAll failed for %v, dbkey %s", tblPath, dbkey) return err } - log.V(4).Infof("Data pulled for dbkey %s: %v", dbkey, fv) + //log.V(4).Infof("Data pulled for dbkey %s: %v", dbkey, fv) if tblPath.jsonTableKey != "" { // If jsonTableKey was prepared, use it err = makeJSON_redis(msi, &tblPath.jsonTableKey, op, fv) } else if (tblPath.tableKey != "" && !useKey) || tblPath.tableName == dbkey { @@ -811,7 +811,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] } log.V(6).Infof("Added idex %v fv %v ", idx, fv) } - log.V(4).Infof("State of map after adding redis data %v", *msi) + //log.V(4).Infof("State of map after adding redis data %v", *msi) return nil } @@ -854,7 +854,7 @@ func tableData2TypedValue(tblPaths []tablePath, op *string) (*gnmipb.TypedValue, log.V(2).Infof("redis HGet failed for %v", tblPath) return nil, err } - log.V(4).Infof("Data pulled for key %s and field %s: %s", key, tblPath.field, val) + //log.V(4).Infof("Data pulled for key %s and field %s: %s", key, tblPath.field, val) // TODO: support multiple table paths return &gnmipb.TypedValue{ Value: &gnmipb.TypedValue_StringVal{ From ffa43c195a42924e4056ed24c59f544eaa039967 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Thu, 12 Oct 2023 20:54:31 +0000 Subject: [PATCH 06/11] Fix UT --- gnmi_server/server_test.go | 76 ++++------------------------------ sonic_data_client/db_client.go | 18 ++++---- 2 files changed, 17 insertions(+), 77 deletions(-) diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index 0bc8d519..fd353d02 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -3717,76 +3717,16 @@ func TestRecoverFromJSONSerializationPanic(t *testing.T) { panicMarshal := func(v interface{}) ([]byte, error) { panic("json.Marshal panics and is unable to serialize JSON") } + mock := gomonkey.ApplyFunc(json.Marshal, panicMarshal) + defer mock.Reset() - s := createServer(t, 8081) - go runServer(t, s) - defer s.s.Stop() - - tests := []struct { - desc string - q client.Query - want []client.Notification - poll int - }{ - { - desc: "poll query COUNTERS/Ethernet*", - poll: 10, - q: client.Query{ - Target: "COUNTERS_DB", - Type: client.Poll, - Queries: []client.Path{{"COUNTERS", "Ethernet*"}}, - TLS: &tls.Config{InsecureSkipVerify: true}, - }, - want: []client.Notification{ - client.Connected{}, - client.Sync{}, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.desc, func(t *testing.T) { - q := tt.q - q.Addrs = []string{"127.0.0.1:8081"} - c := client.New() - var gotNoti []client.Notification - q.NotificationHandler = func(n client.Notification) error { - if nn, ok := n.(client.Update); ok { - nn.TS = time.Unix(0, 200) - gotNoti = append(gotNoti, nn) - } else { - gotNoti = append(gotNoti, n) - } - return nil - } - - wg := new(sync.WaitGroup) - wg.Add(1) - - go func() { - defer wg.Done() - if err := c.Subscribe(context.Background(), q); err != nil { - t.Errorf("c.Subscribe(): got error %v, expected nil", err) - } - }() - - wg.Wait() - - mock := gomonkey.ApplyFunc(json.Marshal, panicMarshal) - defer mock.Reset() - - for i := 0; i < tt.poll; i++ { - if err := c.Poll(); err != nil { - t.Errorf("c.Poll(): got error %v, expected nil", err) - } - } - - if len(gotNoti) == 0 { - t.Errorf("expected non zero notifications") - } + tblPath := sdc.CreateTablePath("STATE_DB", "NEIGH_STATE_TABLE", "|", "10.0.0.57") + msi := make(map[string]interface{}) + sdc.TableData2Msi(&tblPath, true, nil, &msi) - c.Close() - }) + typedValue := Msi2TypedValue(msi) + if typedValue != nil { + t.Errorf("Test should recover from panic and have nil typed value after attempting JSON serialization") } } diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index c2a68c71..1ad0523c 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -725,7 +725,7 @@ func emitJSON(v *map[string]interface{}) ([]byte, error) { defer func() { if r := recover(); r != nil { log.V(2).Infof("Recovered from panic", r) - //log.V(2).Infof("Current state of map to be serialized is: ", *v) + log.V(2).Infof("Current state of map to be serialized is: ", *v) } }() j, err := json.Marshal(*v) @@ -766,13 +766,13 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] dbkeys = []string{tblPath.tableName + tblPath.delimitor + tblPath.tableKey} } - //log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) + log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) //log.V(4).Infof("State of map before adding redis data %v", msi) // Asked to use jsonField and jsonTableKey in the final json value if tblPath.jsonField != "" && tblPath.jsonTableKey != "" { val, err := redisDb.HGet(dbkeys[0], tblPath.field).Result() - //log.V(4).Infof("Data pulled for key %s and field %s: %s", dbkeys[0], tblPath.field, val) + log.V(4).Infof("Data pulled for key %s and field %s: %s", dbkeys[0], tblPath.field, val) if err != nil { log.V(3).Infof("redis HGet failed for %v %v", tblPath, err) // ignore non-existing field which was derived from virtual path @@ -790,7 +790,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] log.V(2).Infof("redis HGetAll failed for %v, dbkey %s", tblPath, dbkey) return err } - //log.V(4).Infof("Data pulled for dbkey %s: %v", dbkey, fv) + log.V(4).Infof("Data pulled for dbkey %s: %v", dbkey, fv) if tblPath.jsonTableKey != "" { // If jsonTableKey was prepared, use it err = makeJSON_redis(msi, &tblPath.jsonTableKey, op, fv) } else if (tblPath.tableKey != "" && !useKey) || tblPath.tableName == dbkey { @@ -815,7 +815,7 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] return nil } -func msi2TypedValue(msi map[string]interface{}) (*gnmipb.TypedValue, error) { +func Msi2TypedValue(msi map[string]interface{}) (*gnmipb.TypedValue, error) { jv, err := emitJSON(&msi) if err != nil { log.V(2).Infof("emitJSON err %s for %v", err, msi) @@ -854,7 +854,7 @@ func tableData2TypedValue(tblPaths []tablePath, op *string) (*gnmipb.TypedValue, log.V(2).Infof("redis HGet failed for %v", tblPath) return nil, err } - //log.V(4).Infof("Data pulled for key %s and field %s: %s", key, tblPath.field, val) + log.V(4).Infof("Data pulled for key %s and field %s: %s", key, tblPath.field, val) // TODO: support multiple table paths return &gnmipb.TypedValue{ Value: &gnmipb.TypedValue_StringVal{ @@ -867,7 +867,7 @@ func tableData2TypedValue(tblPaths []tablePath, op *string) (*gnmipb.TypedValue, return nil, err } } - return msi2TypedValue(msi) + return Msi2TypedValue(msi) } func enqueueFatalMsg(c *DbClient, msg string) { @@ -936,7 +936,7 @@ func dbFieldMultiSubscribe(c *DbClient, gnmiPath *gnmipb.Path, onChange bool, in } sendVal := func(msi map[string]interface{}) error { - val, err := msi2TypedValue(msi) + val, err := Msi2TypedValue(msi) if err != nil { enqueueFatalMsg(c, err.Error()) return err @@ -1193,7 +1193,7 @@ func dbTableKeySubscribe(c *DbClient, gnmiPath *gnmipb.Path, interval time.Durat sendDeleteField = true } delete(msiData, "delete") - val, err := msi2TypedValue(msiData) + val, err := Msi2TypedValue(msiData) if err != nil { return err } From 679058d3abc569255f90dddcc14a9f5f68e64f88 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Thu, 12 Oct 2023 21:06:00 +0000 Subject: [PATCH 07/11] Fix UT --- gnmi_server/server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index fd353d02..881ac761 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -3724,7 +3724,7 @@ func TestRecoverFromJSONSerializationPanic(t *testing.T) { msi := make(map[string]interface{}) sdc.TableData2Msi(&tblPath, true, nil, &msi) - typedValue := Msi2TypedValue(msi) + typedValue := sdc.Msi2TypedValue(msi) if typedValue != nil { t.Errorf("Test should recover from panic and have nil typed value after attempting JSON serialization") } From 74514aaa993ca4e40d426b2da6ad2525275d193e Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Thu, 12 Oct 2023 21:14:04 +0000 Subject: [PATCH 08/11] Fix UT --- gnmi_server/server_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gnmi_server/server_test.go b/gnmi_server/server_test.go index 881ac761..9df8bc72 100644 --- a/gnmi_server/server_test.go +++ b/gnmi_server/server_test.go @@ -3724,9 +3724,9 @@ func TestRecoverFromJSONSerializationPanic(t *testing.T) { msi := make(map[string]interface{}) sdc.TableData2Msi(&tblPath, true, nil, &msi) - typedValue := sdc.Msi2TypedValue(msi) - if typedValue != nil { - t.Errorf("Test should recover from panic and have nil typed value after attempting JSON serialization") + typedValue, err := sdc.Msi2TypedValue(msi) + if typedValue != nil && err != nil { + t.Errorf("Test should recover from panic and have nil TypedValue/Error after attempting JSON serialization") } } From c1f3f2cce76a32c7ebb6c69747142dd69811b682 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Thu, 12 Oct 2023 21:48:35 +0000 Subject: [PATCH 09/11] Add formatting identifier --- sonic_data_client/db_client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index 1ad0523c..c729b03c 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -724,8 +724,8 @@ func emitJSON(v *map[string]interface{}) ([]byte, error) { //j, err := json.MarshalIndent(*v, "", indentString) defer func() { if r := recover(); r != nil { - log.V(2).Infof("Recovered from panic", r) - log.V(2).Infof("Current state of map to be serialized is: ", *v) + log.V(2).Infof("Recovered from panic: %v", r) + log.V(2).Infof("Current state of map to be serialized is: %v", *v) } }() j, err := json.Marshal(*v) From e82518c539abe9cb1044478f2469d75ab0022519 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Fri, 13 Oct 2023 22:12:54 +0000 Subject: [PATCH 10/11] Add log to see state of map --- sonic_data_client/db_client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index c729b03c..c74890a7 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -767,7 +767,6 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] } log.V(4).Infof("dbkeys to be pulled from redis %v", dbkeys) - //log.V(4).Infof("State of map before adding redis data %v", msi) // Asked to use jsonField and jsonTableKey in the final json value if tblPath.jsonField != "" && tblPath.jsonTableKey != "" { @@ -811,11 +810,11 @@ func TableData2Msi(tblPath *tablePath, useKey bool, op *string, msi *map[string] } log.V(6).Infof("Added idex %v fv %v ", idx, fv) } - //log.V(4).Infof("State of map after adding redis data %v", *msi) return nil } func Msi2TypedValue(msi map[string]interface{}) (*gnmipb.TypedValue, error) { + log.V(4).Infof("State of map after adding redis data %v", msi) jv, err := emitJSON(&msi) if err != nil { log.V(2).Infof("emitJSON err %s for %v", err, msi) From 0967832f65d54d4a392f22340022763b7878cbd3 Mon Sep 17 00:00:00 2001 From: Zain Budhwani Date: Mon, 16 Oct 2023 18:07:00 +0000 Subject: [PATCH 11/11] Fix comment --- sonic_data_client/db_client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_data_client/db_client.go b/sonic_data_client/db_client.go index c74890a7..8df9dc0c 100644 --- a/sonic_data_client/db_client.go +++ b/sonic_data_client/db_client.go @@ -820,8 +820,8 @@ func Msi2TypedValue(msi map[string]interface{}) (*gnmipb.TypedValue, error) { log.V(2).Infof("emitJSON err %s for %v", err, msi) return nil, fmt.Errorf("emitJSON err %s for %v", err, msi) } - if jv == nil { // json is nil because of potential panic happen - return nil, fmt.Errorf("emitJSON failed due to panic") + if jv == nil { // json and err is nil because panic potentially happened + return nil, fmt.Errorf("emitJSON failed to grab json value of map due to potential panic") } return &gnmipb.TypedValue{ Value: &gnmipb.TypedValue_JsonIetfVal{