Add non-zero exit + error message to soong metrics
Improves some error messages that would have given little/no information
Bug: 254650145
Test: relevant unit tests
Test: Induce errors and check metrics proto
Change-Id: Ife6116af74af6e62c2f8ae8774e53c28178fb8d0
diff --git a/ui/metrics/metrics.go b/ui/metrics/metrics.go
index 0c62865..ce2d946 100644
--- a/ui/metrics/metrics.go
+++ b/ui/metrics/metrics.go
@@ -125,6 +125,21 @@
}
}
+// SetFatalOrPanicMessage stores a non-zero exit and the relevant message in the latest event if
+// available or the metrics base.
+func (m *Metrics) SetFatalOrPanicMessage(errMsg string) {
+ if m == nil {
+ return
+ }
+ if event := m.EventTracer.peek(); event != nil {
+ event.nonZeroExitCode = true
+ event.errorMsg = &errMsg
+ } else {
+ m.metrics.ErrorMessage = proto.String(errMsg)
+ }
+ m.metrics.NonZeroExit = proto.Bool(true)
+}
+
// BuildConfig stores information about the build configuration.
func (m *Metrics) BuildConfig(b *soong_metrics_proto.BuildConfig) {
m.metrics.BuildConfig = b