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

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

Merged

Conversation

danielayala94
Copy link
Contributor

@danielayala94 danielayala94 commented Dec 10, 2024

Description

This PR eliminates the risk of writing into undefined struct fields in trackException().

Type of Change

Bug fix

Why

Error telemetry instances were lost when hitting MS Build errors sometimes, plus avoid unnecesssary CLI error noise.

Resolves #14184

What

One-line change:
codedErrorStruct.data[f] = (error as any)[f];

instead of:
codedErrorStruct.data.codedError.data[f] = (error as any)[f];

Context:
In error telemetry instances, codedError contains relevant information about an exception thrown from the RNW CLI.
There are two ways to populate codedError: either a errorUtils.CodedError object is passed to trackException(), or a MSBuild error was hit, and the Error object contains any of the following fields: errno, syscall or code. It's in the second scenario where things go wrong.

In trackException(), codedErrorStruct copies the exception data from the Error object that was passed as parameter. This corresponds to codedError.data in the telemetry envelope. However, the MSBuild info was attempted to be copied into codedError.data.codedError.data, causing the Telemetry instance to throw.

Screenshots

N/A

Testing

Added a unit test that makes use of a CustomErrorTest object, based on Error but different from CodedError, to re-create the conditions where the bug was caught.

Changelog

Yes - Fix bug in error telemetry collection.

Microsoft Reviewers: Open in CodeFlow

@danielayala94 danielayala94 requested review from a team as code owners December 10, 2024 21:31
@danielayala94 danielayala94 changed the title Track exception data undefined [Telemetry] Bug fix in codedError.data from trackException() Dec 10, 2024
@danielayala94 danielayala94 merged commit bd901aa into microsoft:main Dec 10, 2024
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Telemetry] Bug in trackException() where data is undefined
2 participants