Skip to content

Commit 0ddfe88

Browse files
committed
Return error when check run configuration is missing
Checks should always be explicitly configured to run or not run in any check mode.
1 parent d2f1189 commit 0ddfe88

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

check/check.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ func RunChecks(project project.Type) {
2525
checkdata.Initialize(project)
2626

2727
for _, checkConfiguration := range checkconfigurations.Configurations() {
28-
if !shouldRun(checkConfiguration, project) {
28+
runCheck, err := shouldRun(checkConfiguration, project)
29+
if err != nil {
30+
feedback.Errorf("Error while determining whether to run check: %v", err)
31+
os.Exit(errorcodes.ErrGeneric)
32+
}
33+
34+
if !runCheck {
2935
// TODO: this should only be printed to log and in verbose mode
3036
fmt.Printf("Skipping check: %s\n", checkConfiguration.ID)
3137
continue
@@ -49,40 +55,39 @@ func RunChecks(project project.Type) {
4955
}
5056

5157
// shouldRun returns whether a given check should be run for the given project under the current tool configuration.
52-
func shouldRun(checkConfiguration checkconfigurations.Type, currentProject project.Type) bool {
58+
func shouldRun(checkConfiguration checkconfigurations.Type, currentProject project.Type) (bool, error) {
5359
configurationCheckModes := configuration.CheckModes(currentProject.SuperprojectType)
5460

5561
if checkConfiguration.ProjectType != currentProject.ProjectType {
56-
return false
62+
return false, nil
5763
}
5864

5965
for _, disableMode := range checkConfiguration.DisableModes {
6066
if configurationCheckModes[disableMode] == true {
61-
return false
67+
return false, nil
6268
}
6369
}
6470

6571
for _, enableMode := range checkConfiguration.EnableModes {
6672
if configurationCheckModes[enableMode] == true {
67-
return true
73+
return true, nil
6874
}
6975
}
7076

7177
// Use default
7278
for _, disableMode := range checkConfiguration.DisableModes {
7379
if disableMode == checkmode.Default {
74-
return false
80+
return false, nil
7581
}
7682
}
7783

7884
for _, enableMode := range checkConfiguration.EnableModes {
7985
if enableMode == checkmode.Default {
80-
return true
86+
return true, nil
8187
}
8288
}
8389

84-
// TODO: this should return an error
85-
return false
90+
return false, fmt.Errorf("Check %s is incorrectly configured", checkConfiguration.ID)
8691
}
8792

8893
// message fills the message template provided by the check configuration with the check output.

0 commit comments

Comments
 (0)