Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.76] [Telemetry] Bug fix in codedError.data from trackException() #14238

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix bug in error telemetry collection.",
"packageName": "@react-native-windows/telemetry",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import * as errorUtils from '../utils/errorUtils';
import * as projectUtils from '../utils/projectUtils';
import * as versionUtils from '../utils/versionUtils';

class CustomTestError extends Error {
// Declare a mock errno field, so it is picked up by trackException() (see syscallExceptionFieldsToCopy)
// to copy it into codedError.data.
errno: string;

constructor(message: string) {
super(message);
this.name = 'CustomTestError';
this.errno = '123';
}
}

export class TelemetryTest extends Telemetry {
protected static hasTestTelemetryProviders: boolean;
protected static testTelemetryProvidersRan: boolean;
Expand Down Expand Up @@ -391,8 +403,16 @@ function verifyTestCommandTelemetryProcessor(
: 'Unknown',
);

// If the exception type is not CodedError but any data got copied into envelope.CodedError.data,
// for instance autolinking error info, build the expected CodedError.data.
let expectedCodedErrorData = {};
if (expectedError instanceof CustomTestError) {
expectedCodedErrorData = {errno: expectedError.errno};
}

expect(codedError.data).toStrictEqual(
(expectedError as errorUtils.CodedError).data ?? {},
(expectedError as errorUtils.CodedError).data ??
expectedCodedErrorData,
);
} else {
// If this is not error scenario, it must be a command successful event.
Expand Down Expand Up @@ -694,3 +714,29 @@ test.each(testTelemetryOptions)(
});
},
);

test.each(testTelemetryOptions)(
'A custom Error-based object with MS Build error info is copied into codedError.data appropriately by trackException()',
async options => {
await TelemetryTest.startTest(options);

const expectedError = new CustomTestError('some message');

// AI eats errors thrown in telemetry processors
const caughtErrors: Error[] = [];
TelemetryTest.addTelemetryInitializer(
verifyTestCommandTelemetryProcessor(
caughtErrors,
'Unknown',
expectedError,
),
);

await runTestCommandE2E(() => testCommandBody(expectedError));

TelemetryTest.endTest(() => {
// Check if any errors were thrown
expect(caughtErrors).toHaveLength(0);
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ export class Telemetry {
const syscallExceptionFieldsToCopy = ['errno', 'syscall', 'code'];
for (const f of syscallExceptionFieldsToCopy) {
if ((error as any)[f]) {
codedErrorStruct.data.codedError.data[f] = (error as any)[f];
codedErrorStruct.data[f] = (error as any)[f];
}
}

Expand Down
Loading