Bug 1316281 - Part 1 - Improve error message for unknown events. r=dexter a=jcristau
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 02 Dec 2016 12:17:12 +0100
changeset 353100 f817cd7da1c1ec82ba921bd593ca77abc2b1e7e6
parent 353099 5004044ea0c1246cb3c8c4f0b0787d277fc2e037
child 353101 52653af186a7463add7d9636ec4441613f83eb7f
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter, jcristau
bugs1316281
milestone52.0a2
Bug 1316281 - Part 1 - Improve error message for unknown events. r=dexter a=jcristau
toolkit/components/telemetry/TelemetryEvent.cpp
toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
--- a/toolkit/components/telemetry/TelemetryEvent.cpp
+++ b/toolkit/components/telemetry/TelemetryEvent.cpp
@@ -514,19 +514,23 @@ TelemetryEvent::RecordEvent(const nsACSt
       return NS_ERROR_FAILURE;
     }
 
     res = ::RecordEvent(lock, timestamp, aCategory, aMethod, aObject, value, extra);
   }
 
   // Trigger warnings or errors where needed.
   switch (res) {
-    case RecordEventResult::UnknownEvent:
-      JS_ReportErrorASCII(cx, "Unknown event.");
+    case RecordEventResult::UnknownEvent: {
+      JS_ReportErrorASCII(cx, R"(Unknown event: ["%s", "%s", "%s"])",
+                          PromiseFlatCString(aCategory).get(),
+                          PromiseFlatCString(aMethod).get(),
+                          PromiseFlatCString(aObject).get());
       return NS_ERROR_INVALID_ARG;
+    }
     case RecordEventResult::InvalidExtraKey:
       LogToBrowserConsole(nsIScriptError::warningFlag,
                           NS_LITERAL_STRING("Invalid extra key for event."));
       return NS_OK;
     case RecordEventResult::StorageLimitReached:
       LogToBrowserConsole(nsIScriptError::warningFlag,
                           NS_LITERAL_STRING("Event storage limit reached."));
       return NS_OK;
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEvents.js
@@ -69,23 +69,23 @@ add_task(function* test_recording() {
     let e = entry.event;
     while ((e.length >= 3) && (e[e.length - 1] === null)) {
       e.pop();
     }
   }
 
   // The following should not result in any recorded events.
   Assert.throws(() => Telemetry.recordEvent("unknown.category", "test1", "object1"),
-                /Error: Unknown event\./,
+                /Error: Unknown event: \["unknown.category", "test1", "object1"\]/,
                 "Should throw on unknown category.");
   Assert.throws(() => Telemetry.recordEvent("telemetry.test", "unknown", "object1"),
-                /Error: Unknown event\./,
+                /Error: Unknown event: \["telemetry.test", "unknown", "object1"\]/,
                 "Should throw on unknown method.");
   Assert.throws(() => Telemetry.recordEvent("telemetry.test", "test1", "unknown"),
-                /Error: Unknown event\./,
+                /Error: Unknown event: \["telemetry.test", "test1", "unknown"\]/,
                 "Should throw on unknown object.");
 
   let checkEvents = (events, expectedEvents) => {
     checkEventFormat(events);
     Assert.equal(events.length, expectedEvents.length,
                  "Snapshot should have the right number of events.");
 
     for (let i = 0; i < events.length; ++i) {