[Telemetry] Bug fix in codedError.data
from trackException()
#14191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aerrorUtils.CodedError
object is passed totrackException()
, or a MSBuild error was hit, and theError
object contains any of the following fields:errno
,syscall
orcode
. It's in the second scenario where things go wrong.In
trackException()
,codedErrorStruct
copies the exception data from theError
object that was passed as parameter. This corresponds tocodedError.data
in the telemetry envelope. However, the MSBuild info was attempted to be copied intocodedError.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 onError
but different fromCodedError
, to re-create the conditions where the bug was caught.Changelog
Yes - Fix bug in error telemetry collection.
Microsoft Reviewers: Open in CodeFlow