Skip to content

Commit 1c994fd

Browse files
committed
refactor: remove always-nil error returns from internal functions
1 parent 0c89ca8 commit 1c994fd

4 files changed

Lines changed: 16 additions & 29 deletions

File tree

binary/cli/cli.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,7 @@ func multiStringToList(arg []string) []string {
462462

463463
func (f *Flags) scanRoots() ([]*scalibrfs.ScanRoot, error) {
464464
if f.RemoteImage != "" {
465-
imageOptions, err := f.scanRemoteImageOptions()
466-
if err != nil {
467-
return nil, err
468-
}
465+
imageOptions := f.scanRemoteImageOptions()
469466
fs, err := scalibrimage.NewFromRemoteName(f.RemoteImage, *imageOptions...)
470467
if err != nil {
471468
return nil, err
@@ -491,7 +488,7 @@ func (f *Flags) scanRoots() ([]*scalibrfs.ScanRoot, error) {
491488
return scanRoots, nil
492489
}
493490

494-
func (f *Flags) scanRemoteImageOptions() (*[]remote.Option, error) {
491+
func (f *Flags) scanRemoteImageOptions() *[]remote.Option {
495492
imageOptions := []remote.Option{
496493
remote.WithAuthFromKeychain(authn.DefaultKeychain),
497494
}
@@ -504,7 +501,7 @@ func (f *Flags) scanRemoteImageOptions() (*[]remote.Option, error) {
504501
},
505502
))
506503
}
507-
return &imageOptions, nil
504+
return &imageOptions
508505
}
509506

510507
// All capabilities are enabled when running SCALIBR as a binary.

binary/proto/proto.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ func ScanResultToProto(r *scalibr.ScanResult) (*spb.ScanResult, error) {
166166

167167
inventories := make([]*spb.Inventory, 0, len(r.Inventories))
168168
for _, i := range r.Inventories {
169-
p, err := inventoryToProto(i)
170-
if err != nil {
171-
return nil, err
172-
}
169+
p := inventoryToProto(i)
173170
inventories = append(inventories, p)
174171
}
175172

@@ -216,9 +213,9 @@ func pluginStatusToProto(s *plugin.Status) *spb.PluginStatus {
216213
}
217214
}
218215

219-
func inventoryToProto(i *extractor.Inventory) (*spb.Inventory, error) {
216+
func inventoryToProto(i *extractor.Inventory) *spb.Inventory {
220217
if i == nil {
221-
return nil, nil
218+
return nil
222219
}
223220
p := converter.ToPURL(i)
224221
inventoryProto := &spb.Inventory{
@@ -233,7 +230,7 @@ func inventoryToProto(i *extractor.Inventory) (*spb.Inventory, error) {
233230
LayerDetails: layerDetailsToProto(i.LayerDetails),
234231
}
235232
setProtoMetadata(i.Metadata, inventoryProto)
236-
return inventoryProto, nil
233+
return inventoryProto
237234
}
238235

239236
func setProtoMetadata(meta any, i *spb.Inventory) {
@@ -614,10 +611,7 @@ func findingToProto(f *detector.Finding) (*spb.Finding, error) {
614611
}
615612
var target *spb.TargetDetails
616613
if f.Target != nil {
617-
i, err := inventoryToProto(f.Target.Inventory)
618-
if err != nil {
619-
return nil, err
620-
}
614+
i := inventoryToProto(f.Target.Inventory)
621615
target = &spb.TargetDetails{
622616
Location: f.Target.Location,
623617
Inventory: i,

extractor/filesystem/language/golang/gobinary/gobinary.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
139139
return []*extractor.Inventory{}, nil
140140
}
141141

142-
inventory, err := e.extractPackagesFromBuildInfo(binfo, input.Path)
143-
e.reportFileExtracted(input.Path, input.Info, err)
144-
return inventory, err
142+
inventory := e.extractPackagesFromBuildInfo(binfo, input.Path)
143+
e.reportFileExtracted(input.Path, input.Info, nil)
144+
return inventory, nil
145145
}
146146

147147
func (e Extractor) reportFileExtracted(path string, fileinfo fs.FileInfo, err error) {
@@ -159,7 +159,7 @@ func (e Extractor) reportFileExtracted(path string, fileinfo fs.FileInfo, err er
159159
})
160160
}
161161

162-
func (e *Extractor) extractPackagesFromBuildInfo(binfo *buildinfo.BuildInfo, filename string) ([]*extractor.Inventory, error) {
162+
func (e *Extractor) extractPackagesFromBuildInfo(binfo *buildinfo.BuildInfo, filename string) []*extractor.Inventory {
163163
res := []*extractor.Inventory{}
164164

165165
validatedGoVers, err := validateGoVersion(binfo.GoVersion)
@@ -190,7 +190,7 @@ func (e *Extractor) extractPackagesFromBuildInfo(binfo *buildinfo.BuildInfo, fil
190190
res = append(res, pkg)
191191
}
192192

193-
return res, nil
193+
return res
194194
}
195195

196196
func validateGoVersion(vers string) (string, error) {

extractor/standalone/containers/containerd/containerd_linux.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,7 @@ func containersFromAPI(ctx context.Context, client CtrdClient) ([]Metadata, erro
184184
for _, ns := range nss {
185185
// For each namespace returned by the API, get the containers metadata.
186186
ctx := namespaces.WithNamespace(ctx, ns)
187-
ctrs, err := containersMetadata(ctx, client, ns, defaultContainerdRootfsPrefix)
188-
if err != nil {
189-
log.Errorf("Could not get a list of containers from the containerd: %v", err)
190-
return nil, err
191-
}
187+
ctrs := containersMetadata(ctx, client, ns, defaultContainerdRootfsPrefix)
192188
// Merge all containers metadata items for all namespaces into a single list.
193189
metadata = append(metadata, ctrs...)
194190
}
@@ -205,7 +201,7 @@ func namespacesFromAPI(ctx context.Context, client CtrdClient) ([]string, error)
205201
return nss, nil
206202
}
207203

208-
func containersMetadata(ctx context.Context, client CtrdClient, namespace string, defaultAbsoluteToBundlePath string) ([]Metadata, error) {
204+
func containersMetadata(ctx context.Context, client CtrdClient, namespace string, defaultAbsoluteToBundlePath string) []Metadata {
209205
var containersMetadata []Metadata
210206

211207
taskService := client.TaskService()
@@ -226,7 +222,7 @@ func containersMetadata(ctx context.Context, client CtrdClient, namespace string
226222

227223
containersMetadata = append(containersMetadata, md)
228224
}
229-
return containersMetadata, nil
225+
return containersMetadata
230226
}
231227

232228
func taskMetadata(ctx context.Context, client CtrdClient, task *task.Process, namespace string, defaultAbsoluteToBundlePath string) (Metadata, error) {

0 commit comments

Comments
 (0)