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

Mutating @api array results in a confusing error message #1739

Closed
apapko opened this issue Feb 25, 2020 · 5 comments
Closed

Mutating @api array results in a confusing error message #1739

apapko opened this issue Feb 25, 2020 · 5 comments

Comments

@apapko
Copy link
Collaborator

apapko commented Feb 25, 2020

Description

Steps to Reproduce

https://developer.salesforce.com/docs/component-library/tools/playground/IaX_i6WN/3/edit

export default class Child extends LightningElement {
    @api
    objects = [];

    connectedCallback() {
        this.objects.push('child mutated label');
    }
}

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

Expected:
Error: Invalid operation. The 'objects' property is read-only.

@git2gus
Copy link

git2gus bot commented Feb 25, 2020

This issue has been linked to a new work item: W-7262124

@ekashida ekashida changed the title mutating @api list produces a bogus error mutating @api array results in a confusing error message Feb 26, 2020
@pmdartus pmdartus changed the title mutating @api array results in a confusing error message Mutating @api array results in a confusing error message Feb 26, 2020
@pmdartus
Copy link
Member

@apapko The error message can't contain the mutate object name since the object name is bound to the current context scope. This information is not available from the ReadOnly proxy.

The best thing we can do here is to print the original target type instead of coercing the original target name to string.

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

@apapko
Copy link
Collaborator Author

apapko commented Feb 26, 2020

@pmdartus i find the Cannot set "0" part to be very confusing as it may not be obvious to a novice user that such message is related to array.push operation. What if we use:
"Invalid operation. @api properties are read-only and cannot be mutated."

@pmdartus
Copy link
Member

We will need to open a new API on the ReadOnlyProxy to parametrize the error message.

@caridy
Copy link
Contributor

caridy commented Feb 28, 2020

I might be able to help here, we do similar stuff in the membrane for locker. Let's chat about it.

divmain added a commit to salesforce/observable-membrane that referenced this issue Jul 22, 2021
divmain added a commit to salesforce/observable-membrane that referenced this issue Jul 23, 2021
divmain added a commit to salesforce/observable-membrane that referenced this issue Jul 23, 2021
divmain added a commit to salesforce/observable-membrane that referenced this issue Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants