Skip to content

Commit

Permalink
Do not crash if buildMetricsPreparedAction null
Browse files Browse the repository at this point in the history
User reports that sometimes they experience `lateinit property
buildMetricsPreparedAction has not been initialized` error, fixed by
Android Studio/IntelliJ Gradle sync.

The root cause of this problem is not known at this moment, but it'll be
better to warn client about it, rather than crashing the build.
  • Loading branch information
wzieba committed May 6, 2024
1 parent 2d91340 commit 6db8f2b
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.automattic.android.measure.reporters

import com.automattic.android.measure.InMemoryReport
import org.gradle.api.Action
import org.gradle.api.logging.Logging
import org.gradle.api.provider.Property

object InMemoryMetricsReporter {

lateinit var buildMetricsPreparedAction: Property<Action<MetricsReport>>
var buildMetricsPreparedAction: Property<Action<MetricsReport>>? = null

fun report(
report: InMemoryReport,
Expand All @@ -18,6 +19,11 @@ object InMemoryMetricsReporter {
override val gradleScanId: String?
get() = gradleScanId
}
buildMetricsPreparedAction.get().execute(result)
if (buildMetricsPreparedAction == null) {
Logging.getLogger(InMemoryMetricsReporter::class.java).warn(
"buildMetricsPreparedAction is not set. Metrics will not be reported."
)
}
buildMetricsPreparedAction?.get()?.execute(result)
}
}

0 comments on commit 6db8f2b

Please sign in to comment.