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

Improve errors for read-only array mutations #63

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

divmain
Copy link
Contributor

@divmain divmain commented Jul 22, 2021

This PR addresses the unhelpful error message discussed in salesforce/lwc#1739, when an attempt is made at mutating a read-only array. Some discussion seems to have occurred offline that wasn't captured in the issue, so the preferred solution wasn't readily apparent. Pinging @apapko @pmdartus @caridy since they previously weighed in.

Before, if someone attempted to mutate a read-only array (using the LWC @api decorator, for example), they would be presented with the following error:

Error: Invalid mutation: Cannot set "0" on "". "" is read-only.

The error now reads:

Error: Invalid mutation: Cannot mutate array at index 0. Array is read-only.

The change addresses the specific concern that was raised but may be insufficient to address larger, related DX concerns. Still, this seemed a reasonable resolution and submitting a PR seemed the easiest to facilitate discussion. Happy to go in a different direction if that is preferred.

Copy link
Contributor

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small nit about isArray.

@divmain divmain force-pushed the dale/readonly-array-errors-W-7262124 branch 2 times, most recently from 8d6d95d to ee66383 Compare July 23, 2021 06:46
@divmain divmain requested a review from nolanlawson July 23, 2021 06:46
Copy link

@kevinv11n kevinv11n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit on formatting, haven't reviewed the logic

src/read-only-handler.ts Outdated Show resolved Hide resolved
@divmain divmain force-pushed the dale/readonly-array-errors-W-7262124 branch from ee66383 to 7d17e6c Compare July 23, 2021 18:06
@divmain divmain requested a review from kevinv11n July 23, 2021 18:07
Copy link
Contributor

@caridy caridy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@divmain divmain merged commit 415b2bd into master Jul 26, 2021
@divmain divmain deleted the dale/readonly-array-errors-W-7262124 branch July 26, 2021 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants