Skip to content

Commit 0c6efb8

Browse files
committed
Add telemetry-only diagnostics
1 parent 3bfcbbf commit 0c6efb8

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,14 @@ func checkForUnsupportedVersions(v versionInfo) (msg, version string) {
709709
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
710710
") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + ")."
711711
version = ""
712-
//TODO: emit diagnostic
712+
diagnostics.EmitUnsupportedVersionGoMod(msg)
713713
}
714714

715715
if v.goInstallationFound && outsideSupportedRange(v.goEnvVersion) {
716716
msg = "The version of Go installed in the environment (" + v.goEnvVersion +
717717
") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + ")."
718718
version = ""
719-
//TODO: emit diagnostic
719+
diagnostics.EmitUnsupportedVersionEnvironment(msg)
720720
}
721721

722722
return msg, version
@@ -728,17 +728,20 @@ func checkForVersionsNotFound(v versionInfo) (msg, version string) {
728728
"`environment.json` file specifying the maximum supported version of Go (" +
729729
maxGoVersion + ")."
730730
version = maxGoVersion
731+
diagnostics.EmitNoGoModAndNoGoEnv(msg)
731732
}
732733

733734
if !v.goInstallationFound && v.goDirectiveFound {
734735
msg = "No version of Go installed. Writing an `environment.json` file specifying the " +
735736
"version of Go found in the `go.mod` file (" + v.goModVersion + ")."
736737
version = v.goModVersion
738+
diagnostics.EmitNoGoEnv(msg)
737739
}
738740

739741
if v.goInstallationFound && !v.goDirectiveFound {
740742
msg = "No `go.mod` file found. Version " + v.goEnvVersion + " installed in the environment."
741743
version = ""
744+
diagnostics.EmitNoGoMod(msg)
742745
}
743746

744747
return msg, version
@@ -751,10 +754,12 @@ func compareVersions(v versionInfo) (msg, version string) {
751754
").\nWriting an `environment.json` file specifying the version of Go from the " +
752755
"`go.mod` file (" + v.goModVersion + ")."
753756
version = v.goModVersion
757+
diagnostics.EmitVersionGoModHigherVersionEnvironment(msg)
754758
} else {
755759
msg = "The version of Go installed in the environment (" + v.goEnvVersion +
756760
") is high enough for the version found in the `go.mod` file (" + v.goModVersion + ")."
757761
version = ""
762+
diagnostics.EmitVersionGoModNotHigherVersionEnvironment(msg)
758763
}
759764

760765
return msg, version

go/extractor/diagnostics/diagnostics.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type visibilityStruct struct {
3030
}
3131

3232
var fullVisibility *visibilityStruct = &visibilityStruct{true, true, true}
33+
var telemetryOnly *visibilityStruct = &visibilityStruct{false, false, true}
3334

3435
type locationStruct struct {
3536
File string `json:"file,omitempty"`
@@ -192,3 +193,80 @@ func EmitRelativeImportPaths() {
192193
noLocation,
193194
)
194195
}
196+
197+
func EmitUnsupportedVersionGoMod(msg string) {
198+
emitDiagnostic(
199+
"go/identify-environment/unsupported-version-in-go-mod",
200+
"Unsupported Go version in `go.mod` file",
201+
msg,
202+
severityError,
203+
telemetryOnly,
204+
noLocation,
205+
)
206+
}
207+
208+
func EmitUnsupportedVersionEnvironment(msg string) {
209+
emitDiagnostic(
210+
"go/identify-environment/unsupported-version-in-environment",
211+
"Unsupported Go version in environment",
212+
msg,
213+
severityError,
214+
telemetryOnly,
215+
noLocation,
216+
)
217+
}
218+
219+
func EmitNoGoModAndNoGoEnv(msg string) {
220+
emitDiagnostic(
221+
"go/identify-environment/no-go-mod-and-no-go-env",
222+
"No `go.mod` file found and no Go version in environment",
223+
msg,
224+
severityNote,
225+
telemetryOnly,
226+
noLocation,
227+
)
228+
}
229+
230+
func EmitNoGoEnv(msg string) {
231+
emitDiagnostic(
232+
"go/identify-environment/no-go-mod-and-no-go-env",
233+
"No Go version in environment",
234+
msg,
235+
severityNote,
236+
telemetryOnly,
237+
noLocation,
238+
)
239+
}
240+
241+
func EmitNoGoMod(msg string) {
242+
emitDiagnostic(
243+
"go/identify-environment/no-go-mod",
244+
"No `go.mod` file found",
245+
msg,
246+
severityNote,
247+
telemetryOnly,
248+
noLocation,
249+
)
250+
}
251+
252+
func EmitVersionGoModHigherVersionEnvironment(msg string) {
253+
emitDiagnostic(
254+
"go/identify-environment/version-go-mod-higher-than-go-env",
255+
"The Go version in `go.mod` file is higher than the Go version in environment",
256+
msg,
257+
severityWarning,
258+
telemetryOnly,
259+
noLocation,
260+
)
261+
}
262+
263+
func EmitVersionGoModNotHigherVersionEnvironment(msg string) {
264+
emitDiagnostic(
265+
"go/identify-environment/version-go-mod-not-higher-than-go-env",
266+
"The Go version in `go.mod` file is not higher than the Go version in environment",
267+
msg,
268+
severityNote,
269+
telemetryOnly,
270+
noLocation,
271+
)
272+
}

0 commit comments

Comments
 (0)