Skip to content

Commit 87ba08b

Browse files
SCALIBR Teamcopybara-github
authored andcommitted
Will remove this block before checking-in
PiperOrigin-RevId: 823162976
1 parent d16eba7 commit 87ba08b

File tree

12 files changed

+1223
-1878
lines changed

12 files changed

+1223
-1878
lines changed

annotator/annotator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Run(ctx context.Context, config *Config, inventory *inventory.Inventory) ([
5959

6060
for _, a := range config.Annotators {
6161
err := a.Annotate(ctx, input, inventory)
62-
statuses = append(statuses, plugin.StatusFromErr(a, false, err))
62+
statuses = append(statuses, plugin.StatusFromErr(a, false, err, nil))
6363
}
6464
return statuses, nil
6565
}

binary/proto/plugin.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ func scanStatusToProto(s *plugin.ScanStatus) *spb.ScanStatus {
6161
return nil
6262
}
6363
statusEnum := structToProtoScanStatus[s.Status]
64-
return &spb.ScanStatus{Status: statusEnum, FailureReason: s.FailureReason}
64+
return &spb.ScanStatus{Status: statusEnum, FailureReason: s.FailureReason, FileErrors: fileErrorsToProto(s.FileErrors)}
65+
}
66+
67+
func fileErrorsToProto(s []*plugin.FileError) []*spb.FileError {
68+
if s == nil {
69+
return nil
70+
}
71+
var res []*spb.FileError
72+
for _, e := range s {
73+
res = append(res, &spb.FileError{FilePath: e.FilePath, ErrorMessage: e.ErrorMessage})
74+
}
75+
return res
6576
}
6677

6778
// --- Proto to Struct
@@ -84,5 +95,16 @@ func scanStatusToStruct(s *spb.ScanStatus) *plugin.ScanStatus {
8495
return nil
8596
}
8697
statusEnum := protoToStructScanStatus[s.GetStatus()]
87-
return &plugin.ScanStatus{Status: statusEnum, FailureReason: s.GetFailureReason()}
98+
return &plugin.ScanStatus{Status: statusEnum, FailureReason: s.GetFailureReason(), FileErrors: fileErrorsToStruct(s.GetFileErrors())}
99+
}
100+
101+
func fileErrorsToStruct(s []*spb.FileError) []*plugin.FileError {
102+
if s == nil {
103+
return nil
104+
}
105+
var res []*plugin.FileError
106+
for _, e := range s {
107+
res = append(res, &plugin.FileError{FilePath: e.GetFilePath(), ErrorMessage: e.GetErrorMessage()})
108+
}
109+
return res
88110
}

binary/proto/plugin_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,31 @@ func TestPluginStatusToProto(t *testing.T) {
5252
},
5353
},
5454
},
55+
{
56+
desc: "converts file errors",
57+
s: &plugin.Status{
58+
Name: "test-plugin-with-file-errors",
59+
Version: 1,
60+
Status: &plugin.ScanStatus{
61+
Status: plugin.ScanStatusPartiallySucceeded,
62+
FileErrors: []*plugin.FileError{
63+
{FilePath: "file1", ErrorMessage: "error1"},
64+
{FilePath: "file2", ErrorMessage: "error2"},
65+
},
66+
},
67+
},
68+
want: &spb.PluginStatus{
69+
Name: "test-plugin-with-file-errors",
70+
Version: 1,
71+
Status: &spb.ScanStatus{
72+
Status: spb.ScanStatus_PARTIALLY_SUCCEEDED,
73+
FileErrors: []*spb.FileError{
74+
{FilePath: "file1", ErrorMessage: "error1"},
75+
{FilePath: "file2", ErrorMessage: "error2"},
76+
},
77+
},
78+
},
79+
},
5580
{
5681
desc: "nil status",
5782
s: &plugin.Status{

binary/proto/scan_result.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ message Inventory {
5353
message ScanStatus {
5454
ScanStatusEnum status = 1;
5555
string failure_reason = 2;
56+
repeated FileError file_errors = 4;
57+
5658
enum ScanStatusEnum {
5759
UNSPECIFIED = 0;
5860
SUCCEEDED = 1;
@@ -67,6 +69,11 @@ message PluginStatus {
6769
ScanStatus status = 3;
6870
}
6971

72+
message FileError {
73+
string file_path = 1;
74+
string error_message = 2;
75+
}
76+
7077
// A software package or library found by an extractor.
7178
// PURL or CPE needs to be set, maybe both.
7279
message Package {

0 commit comments

Comments
 (0)