Skip to content

Commit

Permalink
chore(ytypes): improve node cache error handling
Browse files Browse the repository at this point in the history
Check nil for node cache stored `schema` and `parent`. An `Internal`
error code is returned if either `schema` or `parent` is nil.
  • Loading branch information
jayzhudev committed May 8, 2023
1 parent d085040 commit e3863e9
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ytypes/node_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3863e9

Please sign in to comment.