Skip to content

Commit 4907e57

Browse files
committed
Address review comments
1 parent 2a41e6a commit 4907e57

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ func main() {
251251
modMode := ModUnset
252252
needGopath := true
253253
goDirectiveFound := false
254-
goDirectiveVersion := "1.16"
255254
if _, present := os.LookupEnv("GO111MODULE"); !present {
256255
os.Setenv("GO111MODULE", "auto")
257256
}
@@ -267,7 +266,7 @@ func main() {
267266
if matches != nil {
268267
goDirectiveFound = true
269268
if len(matches) > 1 {
270-
goDirectiveVersion = "v" + string(matches[1])
269+
goDirectiveVersion := "v" + string(matches[1])
271270
if semver.Compare(goDirectiveVersion, getEnvGoSemVer()) >= 0 {
272271
diagnostics.EmitNewerGoVersionNeeded()
273272
}

go/extractor/diagnostics/diagnostics.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package diagnostics
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"log"
67
"os"
78
"time"
@@ -46,14 +47,18 @@ type diagnostic struct {
4647
}
4748

4849
var diagnosticsEmitted, diagnosticsLimit uint = 0, 100
50+
var noDiagnosticDirPrinted bool = false
4951

5052
func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagnosticSeverity, internal, visibilitySP, visibilityCST, visibilityT bool, file string, startLine, startColumn, endLine, endColumn int) {
51-
if diagnosticsEmitted <= diagnosticsLimit {
53+
if diagnosticsEmitted < diagnosticsLimit {
5254
diagnosticsEmitted += 1
5355

5456
diagnosticDir := os.Getenv("CODEQL_EXTRACTOR_GO_DIAGNOSTIC_DIR")
5557
if diagnosticDir == "" {
56-
log.Println("No diagnostic directory set, so not emitting diagnostic")
58+
if !noDiagnosticDirPrinted {
59+
log.Println("No diagnostic directory set, so not emitting diagnostic")
60+
noDiagnosticDirPrinted = true
61+
}
5762
return
5863
}
5964

@@ -73,6 +78,18 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
7378
optLoc,
7479
}
7580

81+
if diagnosticsEmitted == diagnosticsLimit {
82+
d = diagnostic{
83+
time.Now().UTC().Format("2006-01-02T15:04:05.000") + "Z",
84+
sourceStruct{"go/diagnostic-limit-hit", "Some diagnostics were dropped", "go"},
85+
fmt.Sprintf("The number of diagnostics exceeded the limit (%d); the remainder were dropped.", diagnosticsLimit),
86+
string(severityWarning),
87+
false,
88+
visibilityStruct{true, true, true},
89+
nil,
90+
}
91+
}
92+
7693
content, err := json.Marshal(d)
7794
if err != nil {
7895
log.Println(err)
@@ -83,7 +100,12 @@ func emitDiagnostic(sourceid, sourcename, markdownMessage string, severity diagn
83100
log.Println("Failed to create temporary file for diagnostic: ")
84101
log.Println(err)
85102
}
86-
defer targetFile.Close()
103+
defer func() {
104+
if err := targetFile.Close(); err != nil {
105+
log.Println("Failed to close diagnostic file:")
106+
log.Println(err)
107+
}
108+
}()
87109

88110
_, err = targetFile.Write(content)
89111
if err != nil {

0 commit comments

Comments
 (0)