Skip to content

Commit 93bc91f

Browse files
committed
perf: use errors.New and simple string concatenation
1 parent a6b6c5f commit 93bc91f

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

binary/cli/cli.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func validateOutput(output []string) error {
203203
for _, item := range output {
204204
o := strings.Split(item, "=")
205205
if len(o) != 2 {
206-
return fmt.Errorf("invalid output format, should follow a format like -o textproto=result.textproto -o spdx23-json=result.spdx.json")
206+
return errors.New("invalid output format, should follow a format like -o textproto=result.textproto -o spdx23-json=result.spdx.json")
207207
}
208208
oFormat := o[0]
209209
if !slices.Contains(supportedOutputFormats, oFormat) {
@@ -234,7 +234,7 @@ func validateMultiStringArg(arg []string) error {
234234
}
235235
for _, item := range strings.Split(item, ",") {
236236
if len(item) == 0 {
237-
return fmt.Errorf("list item cannot be left empty")
237+
return errors.New("list item cannot be left empty")
238238
}
239239
}
240240
}

detector/cve/cve202016846/cve202016846.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (d Detector) Scan(ctx context.Context, scanRoot *scalibrfs.ScanRoot, ix *in
194194

195195
// CheckForCherrypy checks for the presence of Cherrypy in the server headers.
196196
func CheckForCherrypy(saltIP string, saltServerPort int) bool {
197-
target := fmt.Sprintf("http://%s", net.JoinHostPort(saltIP, strconv.Itoa(saltServerPort)))
197+
target := "http://" + net.JoinHostPort(saltIP, strconv.Itoa(saltServerPort))
198198

199199
client := &http.Client{Timeout: defaultTimeout}
200200
resp, err := client.Get(target)

extractor/filesystem/containers/containerd/containerd_dummy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package containerd
1818

1919
import (
2020
"context"
21-
"fmt"
21+
"errors"
2222

2323
"github.com/google/osv-scalibr/extractor"
2424
"github.com/google/osv-scalibr/extractor/filesystem"
@@ -66,7 +66,7 @@ func (e Extractor) FileRequired(_ filesystem.FileAPI) bool {
6666

6767
// Extract not implemented.
6868
func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]*extractor.Inventory, error) {
69-
return nil, fmt.Errorf("not supported")
69+
return nil, errors.New("not supported")
7070
}
7171

7272
// ToPURL not implemented.

extractor/filesystem/os/rpm/rpm_dummy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package rpm
1818

1919
import (
2020
"context"
21-
"fmt"
21+
"errors"
2222
"time"
2323

2424
"github.com/google/osv-scalibr/extractor"
@@ -73,7 +73,7 @@ func (e Extractor) FileRequired(_ filesystem.FileAPI) bool {
7373

7474
// Extract extracts packages from rpm status files passed through the scan input.
7575
func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]*extractor.Inventory, error) {
76-
return nil, fmt.Errorf("not supported")
76+
return nil, errors.New("not supported")
7777
}
7878

7979
// ToPURL converts an inventory created by this extractor into a PURL.

extractor/standalone/containers/containerd/containerd_dummy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package containerd
1818

1919
import (
2020
"context"
21-
"fmt"
21+
"errors"
2222

2323
"github.com/google/osv-scalibr/extractor"
2424
"github.com/google/osv-scalibr/extractor/standalone"
@@ -67,7 +67,7 @@ func (e Extractor) Requirements() *plugin.Capabilities { return &plugin.Capabili
6767

6868
// Extract is a no-op for non-Linux.
6969
func (e *Extractor) Extract(ctx context.Context, input *standalone.ScanInput) ([]*extractor.Inventory, error) {
70-
return nil, fmt.Errorf("only supported on Linux")
70+
return nil, errors.New("only supported on Linux")
7171
}
7272

7373
// ToPURL converts an inventory created by this extractor into a PURL.

extractor/standalone/os/netports/netports_dummy.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package netports
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223

2324
"github.com/google/osv-scalibr/extractor"
@@ -52,7 +53,7 @@ func (e Extractor) Requirements() *plugin.Capabilities {
5253

5354
// Extract is a no-op for non Linux.
5455
func (e *Extractor) Extract(ctx context.Context, input *standalone.ScanInput) ([]*extractor.Inventory, error) {
55-
return nil, fmt.Errorf("only supported on Linux")
56+
return nil, errors.New("only supported on Linux")
5657
}
5758

5859
// ToPURL converts an inventory created by this extractor into a PURL.

0 commit comments

Comments
 (0)