Skip to content

Commit

Permalink
Added some nill checks.
Browse files Browse the repository at this point in the history
In case, you never know.
  • Loading branch information
daveshanley committed Aug 5, 2024
1 parent 82f5800 commit 8f9eb65
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions datamodel/low/node_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ func (nm *NodeMap) AddNode(key int, node *yaml.Node) {
// GetNodes will return the map of nodes
func (nm *NodeMap) GetNodes() map[int][]*yaml.Node {
composed := make(map[int][]*yaml.Node)
nm.Nodes.Range(func(key, value interface{}) bool {
if v, ok := value.([]*yaml.Node); ok {
composed[key.(int)] = v
}
if v, ok := value.(*yaml.Node); ok {
composed[key.(int)] = []*yaml.Node{v}
}
if nm.Nodes != nil {
nm.Nodes.Range(func(key, value interface{}) bool {
if v, ok := value.([]*yaml.Node); ok {
composed[key.(int)] = v
}
if v, ok := value.(*yaml.Node); ok {
composed[key.(int)] = []*yaml.Node{v}
}

return true
})
return true
})
}
if len(composed) <= 0 {
composed[0] = []*yaml.Node{} // return an empty slice if there are no nodes
}
Expand Down Expand Up @@ -134,12 +136,14 @@ func ExtractExtensionNodes(_ context.Context,
} else {
results = append(results, v.ValueNode)
}
if k.KeyNode.Line == v.ValueNode.Line {
nodeMap.Store(k.KeyNode.Line, results)
} else {
nodeMap.Store(k.KeyNode.Line, results[0])
for _, y := range results[1:] {
nodeMap.Store(y.Line, []*yaml.Node{y})
if nodeMap != nil {
if k.KeyNode.Line == v.ValueNode.Line {
nodeMap.Store(k.KeyNode.Line, results)
} else {
nodeMap.Store(k.KeyNode.Line, results[0])
for _, y := range results[1:] {
nodeMap.Store(y.Line, []*yaml.Node{y})
}
}
}
}
Expand Down

0 comments on commit 8f9eb65

Please sign in to comment.