From e3863e99cfb6a536b31a3b64cbbb6c95fc0f901a Mon Sep 17 00:00:00 2001 From: Jay Zhu Date: Mon, 8 May 2023 17:40:06 -0600 Subject: [PATCH] chore(ytypes): improve node cache error handling Check nil for node cache stored `schema` and `parent`. An `Internal` error code is returned if either `schema` or `parent` is nil. --- ytypes/node_cache.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ytypes/node_cache.go b/ytypes/node_cache.go index e9024b77..f1af617a 100644 --- a/ytypes/node_cache.go +++ b/ytypes/node_cache.go @@ -110,6 +110,18 @@ func (c *NodeCache) set(path *gpb.Path, val interface{}, opts ...SetNodeOpt) (se parent := &nodeInfo.parent root := &nodeInfo.root + if schema == nil { + err = status.Error(codes.Internal, "cache: the schema is nil") + c.mu.Unlock() + return + } + + if parent == nil { + err = status.Error(codes.Internal, "cache: the parent is nil") + c.mu.Unlock() + return + } + // Set value in the config tree. if (*schema).Parent != nil && (*schema).Parent.IsContainer() { var encoding Encoding