Skip to content

Commit 44ad5f5

Browse files
⚠️ Removing the error field from result (#1853)
- Removing the error field from result - #1393 Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
1 parent 1f3861b commit 44ad5f5

26 files changed

+54
-87
lines changed

checker/check_result.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ const (
7979
// nolint:govet
8080
type CheckResult struct {
8181
// TODO(#1393): Remove old structure after deprecation.
82-
Error error `json:"-"`
8382
Name string
8483
Details []string
8584
Confidence int
@@ -88,7 +87,7 @@ type CheckResult struct {
8887
// UPGRADEv2: New structure. Omitting unchanged Name field
8988
// for simplicity.
9089
Version int `json:"-"` // Default value of 0 indicates old structure.
91-
Error2 error `json:"-"` // Runtime error indicate a filure to run the check.
90+
Error error `json:"-"` // Runtime error indicate a filure to run the check.
9291
Details2 []CheckDetail `json:"-"` // Details of tests and sub-checks
9392
Score int `json:"-"` // {[-1,0...10], -1 = Inconclusive}
9493
Reason string `json:"-"` // A sentence describing the check result (score, etc)
@@ -161,12 +160,11 @@ func CreateResultWithScore(name, reason string, score int) CheckResult {
161160
return CheckResult{
162161
Name: name,
163162
// Old structure.
164-
Error: nil,
165163
Confidence: MaxResultScore,
166164
Pass: pass,
167165
// New structure.
168166
Version: 2,
169-
Error2: nil,
167+
Error: nil,
170168
Score: score,
171169
Reason: reason,
172170
}
@@ -186,12 +184,11 @@ func CreateProportionalScoreResult(name, reason string, b, t int) CheckResult {
186184
return CheckResult{
187185
Name: name,
188186
// Old structure.
189-
Error: nil,
190187
Confidence: MaxResultConfidence,
191188
Pass: pass,
192189
// New structure.
193190
Version: 2,
194-
Error2: nil,
191+
Error: nil,
195192
Score: score,
196193
Reason: NormalizeReason(reason, score),
197194
}
@@ -232,12 +229,11 @@ func CreateRuntimeErrorResult(name string, e error) CheckResult {
232229
return CheckResult{
233230
Name: name,
234231
// Old structure.
235-
Error: e,
236232
Confidence: 0,
237233
Pass: false,
238234
// New structure.
239235
Version: 2,
240-
Error2: e,
236+
Error: e,
241237
Score: InconclusiveResultScore,
242238
Reason: e.Error(), // Note: message already accessible by caller thru `Error`.
243239
}

checker/check_runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func logStats(ctx context.Context, startTime time.Time, result *CheckResult) err
7777
opencensusstats.Record(ctx, stats.CheckRuntimeInSec.M(runTimeInSecs))
7878

7979
if result.Error != nil {
80-
ctx, err := tag.New(ctx, tag.Upsert(stats.ErrorName, sce.GetName(result.Error2)))
80+
ctx, err := tag.New(ctx, tag.Upsert(stats.ErrorName, sce.GetName(result.Error)))
8181
if err != nil {
8282
return sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("tag.New: %v", err))
8383
}
@@ -109,9 +109,9 @@ func (r *Runner) Run(ctx context.Context, c Check) CheckResult {
109109
checkRequest.Ctx = ctx
110110
checkRequest.Dlogger = l
111111
res = c.Fn(&checkRequest)
112-
if res.Error2 != nil && errors.Is(res.Error2, sce.ErrRepoUnreachable) {
112+
if res.Error != nil && errors.Is(res.Error, sce.ErrRepoUnreachable) {
113113
checkRequest.Dlogger.Warn(&LogMessage{
114-
Text: fmt.Sprintf("%v", res.Error2),
114+
Text: fmt.Sprintf("%v", res.Error),
115115
})
116116
continue
117117
}

checks/code_review_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestCodereview(t *testing.T) {
207207
res := CodeReview(&req)
208208

209209
if tt.err != nil {
210-
if res.Error2 == nil {
210+
if res.Error == nil {
211211
t.Errorf("Expected error %v, got nil", tt.err)
212212
}
213213
// return as we don't need to check the rest of the fields.

checks/contributors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func TestContributors(t *testing.T) {
175175
res := Contributors(&req)
176176

177177
if tt.err != nil {
178-
if res.Error2 == nil {
178+
if res.Error == nil {
179179
t.Errorf("Expected error %v, got nil", tt.err)
180180
}
181181
// return as we don't need to check the rest of the fields.

checks/evaluation/binary_artifacts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ func TestBinaryArtifacts(t *testing.T) {
277277
t.Parallel()
278278
got := BinaryArtifacts(tt.args.name, tt.args.dl, tt.args.r)
279279
if tt.wantErr {
280-
if got.Error2 == nil {
281-
t.Errorf("BinaryArtifacts() error = %v, wantErr %v", got.Error2, tt.wantErr)
280+
if got.Error == nil {
281+
t.Errorf("BinaryArtifacts() error = %v, wantErr %v", got.Error, tt.wantErr)
282282
}
283283
} else {
284284
if got.Score != tt.want.Score {

checks/evaluation/dependency_update_tool_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func TestDependencyUpdateTool(t *testing.T) {
7070
},
7171
},
7272
want: checker.CheckResult{
73-
Score: 0,
74-
Error2: nil,
73+
Score: 0,
74+
Error: nil,
7575
},
7676
err: false,
7777
expected: scut.TestReturn{
@@ -104,8 +104,8 @@ func TestDependencyUpdateTool(t *testing.T) {
104104
},
105105
},
106106
want: checker.CheckResult{
107-
Score: 10,
108-
Error2: nil,
107+
Score: 10,
108+
Error: nil,
109109
},
110110
expected: scut.TestReturn{
111111
Error: nil,
@@ -131,8 +131,8 @@ func TestDependencyUpdateTool(t *testing.T) {
131131
},
132132
},
133133
want: checker.CheckResult{
134-
Score: -1,
135-
Error2: nil,
134+
Score: -1,
135+
Error: nil,
136136
},
137137
expected: scut.TestReturn{
138138
Error: sce.ErrScorecardInternal,
@@ -147,8 +147,8 @@ func TestDependencyUpdateTool(t *testing.T) {
147147
dl: &scut.TestDetailLogger{},
148148
},
149149
want: checker.CheckResult{
150-
Score: -1,
151-
Error2: nil,
150+
Score: -1,
151+
Error: nil,
152152
},
153153
expected: scut.TestReturn{
154154
Error: sce.ErrScorecardInternal,
@@ -167,8 +167,8 @@ func TestDependencyUpdateTool(t *testing.T) {
167167
if tt.want.Score != got.Score {
168168
t.Errorf("DependencyUpdateTool() got Score = %v, want %v for %v", got.Score, tt.want.Score, tt.name)
169169
}
170-
if tt.err && got.Error2 == nil {
171-
t.Errorf("DependencyUpdateTool() error = %v, want %v for %v", got.Error2, tt.want.Error2, tt.name)
170+
if tt.err && got.Error == nil {
171+
t.Errorf("DependencyUpdateTool() error = %v, want %v for %v", got.Error, tt.want.Error, tt.name)
172172
return
173173
}
174174

checks/evaluation/webhooks_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ func TestWebhooks(t *testing.T) {
139139
t.Parallel()
140140
got := Webhooks(tt.args.name, tt.args.dl, tt.args.r)
141141
if tt.wantErr {
142-
if got.Error2 == nil {
143-
t.Errorf("Webhooks() error = %v, wantErr %v", got.Error2, tt.wantErr)
142+
if got.Error == nil {
143+
t.Errorf("Webhooks() error = %v, wantErr %v", got.Error, tt.wantErr)
144144
}
145145
} else {
146146
if got.Score != tt.want.Score {

checks/fuzzing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ func TestFuzzing(t *testing.T) {
295295
}
296296

297297
result := Fuzzing(&req)
298-
if (result.Error2 != nil) != tt.wantErr {
299-
t.Errorf("Fuzzing() error = %v, wantErr %v", result.Error2, tt.wantErr)
298+
if (result.Error != nil) != tt.wantErr {
299+
t.Errorf("Fuzzing() error = %v, wantErr %v", result.Error, tt.wantErr)
300300
return
301301
}
302302

checks/maintained_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func Test_Maintained(t *testing.T) {
345345
res := Maintained(&req)
346346

347347
if tt.err != nil {
348-
if res.Error2 == nil {
348+
if res.Error == nil {
349349
t.Errorf("Expected error %v, got nil", tt.err)
350350
}
351351
// return as we don't need to check the rest of the fields.

checks/pinned_dependencies_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func TestGithubWorkflowPinning(t *testing.T) {
128128

129129
s, e := testIsGitHubActionsWorkflowPinned(p, content, &dl)
130130
actual := checker.CheckResult{
131-
Score: s,
132-
Error2: e,
131+
Score: s,
132+
Error: e,
133133
}
134134
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
135135
t.Fail()
@@ -221,8 +221,8 @@ func TestNonGithubWorkflowPinning(t *testing.T) {
221221

222222
s, e := testIsGitHubActionsWorkflowPinned(p, content, &dl)
223223
actual := checker.CheckResult{
224-
Score: s,
225-
Error2: e,
224+
Score: s,
225+
Error: e,
226226
}
227227
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
228228
t.Fail()
@@ -268,8 +268,8 @@ func TestGithubWorkflowPkgManagerPinning(t *testing.T) {
268268

269269
s, e := testValidateGitHubWorkflowScriptFreeOfInsecureDownloads(p, content, &dl)
270270
actual := checker.CheckResult{
271-
Score: s,
272-
Error2: e,
271+
Score: s,
272+
Error: e,
273273
}
274274

275275
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
@@ -392,8 +392,8 @@ func TestDockerfilePinning(t *testing.T) {
392392
dl := scut.TestDetailLogger{}
393393
s, e := testValidateDockerfileIsPinned(tt.filename, content, &dl)
394394
actual := checker.CheckResult{
395-
Score: s,
396-
Error2: e,
395+
Score: s,
396+
Error: e,
397397
}
398398
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
399399
t.Fail()
@@ -781,8 +781,8 @@ func TestDockerfilePinningWihoutHash(t *testing.T) {
781781
dl := scut.TestDetailLogger{}
782782
s, e := testValidateDockerfileIsPinned(tt.filename, content, &dl)
783783
actual := checker.CheckResult{
784-
Score: s,
785-
Error2: e,
784+
Score: s,
785+
Error: e,
786786
}
787787
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
788788
t.Fail()
@@ -970,8 +970,8 @@ func TestDockerfileScriptDownload(t *testing.T) {
970970
dl := scut.TestDetailLogger{}
971971
s, e := testValidateDockerfileIsFreeOfInsecureDownloads(tt.filename, content, &dl)
972972
actual := checker.CheckResult{
973-
Score: s,
974-
Error2: e,
973+
Score: s,
974+
Error: e,
975975
}
976976
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
977977
t.Fail()
@@ -1013,8 +1013,8 @@ func TestDockerfileScriptDownloadInfo(t *testing.T) {
10131013
dl := scut.TestDetailLogger{}
10141014
s, e := testValidateDockerfileIsFreeOfInsecureDownloads(tt.filename, content, &dl)
10151015
actual := checker.CheckResult{
1016-
Score: s,
1017-
Error2: e,
1016+
Score: s,
1017+
Error: e,
10181018
}
10191019
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
10201020
t.Fail()
@@ -1123,8 +1123,8 @@ func TestShellScriptDownload(t *testing.T) {
11231123
dl := scut.TestDetailLogger{}
11241124
s, e := testValidateShellScriptIsFreeOfInsecureDownloads(tt.filename, content, &dl)
11251125
actual := checker.CheckResult{
1126-
Score: s,
1127-
Error2: e,
1126+
Score: s,
1127+
Error: e,
11281128
}
11291129
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
11301130
t.Fail()
@@ -1178,8 +1178,8 @@ func TestShellScriptDownloadPinned(t *testing.T) {
11781178
dl := scut.TestDetailLogger{}
11791179
s, e := testValidateShellScriptIsFreeOfInsecureDownloads(tt.filename, content, &dl)
11801180
actual := checker.CheckResult{
1181-
Score: s,
1182-
Error2: e,
1181+
Score: s,
1182+
Error: e,
11831183
}
11841184
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
11851185
t.Fail()
@@ -1257,8 +1257,8 @@ func TestGitHubWorflowRunDownload(t *testing.T) {
12571257

12581258
s, e := testValidateGitHubWorkflowScriptFreeOfInsecureDownloads(p, content, &dl)
12591259
actual := checker.CheckResult{
1260-
Score: s,
1261-
Error2: e,
1260+
Score: s,
1261+
Error: e,
12621262
}
12631263
if !scut.ValidateTestReturn(t, tt.name, &tt.expected, &actual, &dl) {
12641264
t.Fail()

0 commit comments

Comments
 (0)