Skip to content

Commit

Permalink
Merge pull request #391 from ackama:extractor/return-nil
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 716135652
  • Loading branch information
copybara-github committed Jan 16, 2025
2 parents 6d1c6b6 + 434f624 commit cfd5e4b
Show file tree
Hide file tree
Showing 22 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestExtractor_Extract_v1(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-json.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/cpp/conanlock/conanlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]

err := json.NewDecoder(input.Reader).Decode(&parsedLockfile)
if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

inv := parseConanLock(*parsedLockfile)
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/golang/gobinary/gobinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
buf := bytes.NewBuffer([]byte{})
_, err := io.Copy(buf, input.Reader)
if err != nil {
return []*extractor.Inventory{}, err
return nil, err
}
readerAt = bytes.NewReader(buf.Bytes())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
}

if err := scanner.Err(); err != nil {
return []*extractor.Inventory{}, fmt.Errorf("failed to read: %w", err)
return nil, fmt.Errorf("failed to read: %w", err)
}

return pkgs, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := xml.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

pkgs := make([]*extractor.Inventory, 0, len(parsedLockfile.Components))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestExtractor_Extract(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-xml.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/java/pomxml/pomxml.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := xml.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

details := map[string]*extractor.Inventory{}
Expand Down
4 changes: 2 additions & 2 deletions extractor/filesystem/language/java/pomxml/pomxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ func TestExtractor_Extract(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-pom.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Name: "invalid syntax",
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/invalid-syntax.xml",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := yaml.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil && !errors.Is(err, io.EOF) {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

// this will happen if the file is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExtractor_Extract(t *testing.T) {
Path: "testdata/not-yaml.txt",
},
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
},
{
Name: "invalid dep path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := json.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

packages := make(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestExtractor_Extract(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-json.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/python/pdmlock/pdmlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]

_, err := toml.NewDecoder(input.Reader).Decode(&parsedLockFile)
if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}
packages := make([]*extractor.Inventory, 0, len(parsedLockFile.Packages))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestExtractor_Extract(t *testing.T) {
Path: "testdata/not-toml.txt",
},
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
},
{
Name: "no packages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := json.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

details := make(map[string]*extractor.Inventory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExtractor_Extract(t *testing.T) {
Path: "testdata/not-json.txt",
},
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
},
{
Name: "no packages",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
_, err := toml.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

packages := make([]*extractor.Inventory, 0, len(parsedLockfile.Packages))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExtractor_Extract(t *testing.T) {
Path: "testdata/not-toml.txt",
},
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
},
{
Name: "no packages",
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/r/renvlock/renvlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (e Extractor) Extract(ctx context.Context, input *filesystem.ScanInput) ([]
err := json.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

packages := make([]*extractor.Inventory, 0, len(parsedLockfile.Packages))
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/r/renvlock/renvlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestExtractor_Extract(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-json.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down
2 changes: 1 addition & 1 deletion extractor/filesystem/language/rust/cargolock/cargolock.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (e Extractor) Extract(_ context.Context, input *filesystem.ScanInput) ([]*e
_, err := toml.NewDecoder(input.Reader).Decode(&parsedLockfile)

if err != nil {
return []*extractor.Inventory{}, fmt.Errorf("could not extract from %s: %w", input.Path, err)
return nil, fmt.Errorf("could not extract from %s: %w", input.Path, err)
}

packages := make([]*extractor.Inventory, 0, len(parsedLockfile.Packages))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestExtractor_Extract(t *testing.T) {
InputConfig: extracttest.ScanInputMockConfig{
Path: "testdata/not-toml.txt",
},
WantInventory: []*extractor.Inventory{},
WantInventory: nil,
WantErr: extracttest.ContainsErrStr{Str: "could not extract from"},
},
{
Expand Down

0 comments on commit cfd5e4b

Please sign in to comment.