Skip to content

Commit 68345ab

Browse files
committed
Record error and add testGetNumRecorded errors API to uuid metric
1 parent 25fcbc9 commit 68345ab

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

glean/src/core/metrics/types/uuid.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MetricType } from "../index.js";
77
import { generateUUIDv4, isString } from "../../utils.js";
88
import { Context } from "../../context.js";
99
import { Metric } from "../metric.js";
10+
import { ErrorType, recordError, testGetNumRecordedErrors } from "../../error_recording.js";
1011

1112
// Loose UUID regex for checking if a string has a UUID _shape_. Does not contain version checks.
1213
//
@@ -67,8 +68,11 @@ class UUIDMetricType extends MetricType {
6768
try {
6869
metric = new UUIDMetric(value);
6970
} catch {
70-
// TODO: record error once Bug 1682574 is resolved.
71-
console.warn(`"${value}" is not a valid UUID. Ignoring`);
71+
await recordError(
72+
instance,
73+
ErrorType.InvalidValue,
74+
`"${value}" is not a valid UUID.`
75+
);
7276
return;
7377
}
7478

@@ -123,6 +127,19 @@ class UUIDMetricType extends MetricType {
123127
});
124128
return metric;
125129
}
130+
131+
/**
132+
* Returns the number of errors recorded for the given metric.
133+
*
134+
* @param errorType The type of the error recorded.
135+
* @param pingName represents the name of the ping to retrieve the metric for.
136+
* Defaults to the first value in `sendInPings`.
137+
*
138+
* @return the number of errors recorded for the metric.
139+
*/
140+
async testGetNumRecordedErrors(errorType: string, ping: string = this.sendInPings[0]): Promise<number> {
141+
return testGetNumRecordedErrors(this, errorType as ErrorType, ping);
142+
}
126143
}
127144

128145
export default UUIDMetricType;

glean/tests/core/metrics/uuid.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Glean from "../../../src/core/glean";
99
import UUIDMetricType from "../../../src/core/metrics/types/uuid";
1010
import { Lifetime } from "../../../src/core/metrics/lifetime";
1111
import { Context } from "../../../src/core/context";
12+
import { ErrorType } from "../../../src/core/error_recording";
1213

1314
describe("UUIDMetric", function() {
1415
const testAppId = `gleanjs.test.${this.title}`;
@@ -45,8 +46,6 @@ describe("UUIDMetric", function() {
4546
});
4647

4748
it("attempting to set an invalid uuid is a no-op", async function() {
48-
Glean.setUploadEnabled(false);
49-
5049
const metric = new UUIDMetricType({
5150
category: "aCategory",
5251
name: "aUUIDMetric",
@@ -57,6 +56,7 @@ describe("UUIDMetric", function() {
5756

5857
metric.set("not valid");
5958
assert.strictEqual(await metric.testGetValue("aPing"), undefined);
59+
assert.strictEqual(await metric.testGetNumRecordedErrors(ErrorType.InvalidValue), 1);
6060
});
6161

6262
it("ping payload is correct", async function() {

0 commit comments

Comments
 (0)