Closed Bug 1655112 Opened 6 years ago Closed 5 years ago

Unintuitive error message when testGetValue does not have a value

Categories

(Data Platform and Tools :: Glean: SDK, defect, P2)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: mcomella, Assigned: mdroettboom)

Details

Attachments

(2 files)

Attached file thrown-exception.txt

Example code:

@Test
fun showErrorMessage() {
    org.mozilla.fenix.GleanMetrics.StorageStats.appBytes.testGetValue()
}

This will throw an error (full trace attached):

java.lang.NullPointerException
	at mozilla.telemetry.glean.private.MemoryDistributionMetricType.testGetValue(MemoryDistributionMetricType.kt:128)
	at mozilla.telemetry.glean.private.MemoryDistributionMetricType.testGetValue$default(MemoryDistributionMetricType.kt:123)
...

Usually, a NullPointerException implies programmer error so I interpret this error to mean either:

  • I messed up by using a null reference
  • There's a bug in a library for that reason

However, the real issue is that there is no value set in StorageStats.appBytes and it requires a little debugging to realize that (I had to look at the glean source to figure it out).

I think it would be more intuitive to do one of, in order of preference:

  • throw a custom exception (GleanTestException?) with a message like, "metric must have value set if testGetValue is called. See testHasValue to check for existence"
  • throw an IllegalStateException (which is more intuitive than NPE) with a similar message
  • Add a similar message to the existing NullPointerException
Priority: -- → P3
Whiteboard: [telemetry:glean-rs:m?]
Priority: P3 → P2
Whiteboard: [telemetry:glean-rs:m?]
Assignee: nobody → mdroettboom
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: