Skip to content

Commit

Permalink
bug: fixed nil-pointer exceptions (#395)
Browse files Browse the repository at this point in the history
* fix(issue_match): removed severity resolver

* bug: fix nilpointer and error conditions

* revert:  go sum changes
  • Loading branch information
drochow authored Nov 19, 2024
1 parent 04a4f2f commit cdc4e4d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scanner/k8s-assets/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ func (p *Processor) ProcessService(ctx context.Context, serviceInfo scanner.Serv
createSupportGroupResp, err := client.CreateSupportGroup(ctx, *p.Client, createSupportGroupInput)
if err != nil {
return "", fmt.Errorf("failed to create SupportGroup %s: %w", serviceInfo.SupportGroup, err)
} else if createSupportGroupResp.CreateSupportGroup == nil {
return "", fmt.Errorf("failed to create SupportGroup as CreateSupportGroup response is nil")
} else {
supportGroupId = createSupportGroupResp.CreateSupportGroup.Id
}
Expand Down Expand Up @@ -153,7 +155,7 @@ func (p *Processor) getSupportGroup(ctx context.Context, serviceInfo scanner.Ser
}

// Return the first item
if listSupportGroupsResp.SupportGroups.TotalCount > 0 && len(listSupportGroupsResp.SupportGroups.Edges) > 0 {
if listSupportGroupsResp != nil && listSupportGroupsResp.SupportGroups.TotalCount > 0 && len(listSupportGroupsResp.SupportGroups.Edges) > 0 {
supportGroupId = listSupportGroupsResp.SupportGroups.Edges[0].Node.Id
} else {
return "", fmt.Errorf("ListSupportGroups returned no SupportGroupID")
Expand Down Expand Up @@ -246,7 +248,7 @@ func (p *Processor) getComponentVersion(ctx context.Context, image string, versi
return "", fmt.Errorf("Couldn't list ComponentVersion")
}

if listCompoVersResp.ComponentVersions.TotalCount > 0 {
if listCompoVersResp != nil && listCompoVersResp.ComponentVersions.TotalCount > 0 {
return listCompoVersResp.ComponentVersions.Edges[0].Node.Id, nil
}

Expand Down Expand Up @@ -309,6 +311,10 @@ func (p *Processor) ProcessContainer(
return fmt.Errorf("failed to create Component. %w", err)
}

if componentId == "" {
return fmt.Errorf("failed to create Component. ComponentId is empty")
}

//
// Create new ComponentVersion
//
Expand Down Expand Up @@ -361,6 +367,8 @@ func (p *Processor) createComponent(ctx context.Context, input *client.Component
createComponentResp, err := client.CreateComponent(ctx, *p.Client, input)
if err != nil {
return "", fmt.Errorf("failed to create Component: %w", err)
} else if createComponentResp.CreateComponent == nil {
return "", fmt.Errorf("failed to create Component as CreateComponent response is nil")
}

log.WithFields(log.Fields{
Expand All @@ -379,6 +387,8 @@ func (p *Processor) createComponentVersion(ctx context.Context, imageVersion str
createCompVersionResp, err := client.CreateComponentVersion(ctx, *p.Client, componentVersionInput)
if err != nil {
return "", fmt.Errorf("failed to create ComponentVersion: %w", err)
} else if createCompVersionResp.CreateComponentVersion == nil {
return "", fmt.Errorf("failed to create ComponentVersion as CreateComponentVersion response is nil")
}

log.WithFields(log.Fields{
Expand All @@ -393,6 +403,8 @@ func (p *Processor) createComponentInstance(ctx context.Context, input *client.C
createCompInstResp, err := client.CreateComponentInstance(ctx, *p.Client, input)
if err != nil {
return "", fmt.Errorf("failed to create ComponentInstance: %w", err)
} else if createCompInstResp.CreateComponentInstance == nil {
return "", fmt.Errorf("failed to create ComponentInstance as CreateComponentInstance response is nil")
}

log.WithFields(log.Fields{
Expand Down

0 comments on commit cdc4e4d

Please sign in to comment.