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

[3.1.0] Assertion Failed: You attempted to access the length property #16495

Closed
boris-petrov opened this issue Apr 11, 2018 · 3 comments
Closed
Assignees
Milestone

Comments

@boris-petrov
Copy link
Contributor

boris-petrov commented Apr 11, 2018

We have the following code (inside prototype-extensions.js):

Ember.A.prototype.flatten = Array.prototype.flatten = function () {
    var result = Ember.A();
    this.forEach(function (element) {
        if (Ember.isArray(element)) {
            result.pushObjects(element.flatten());
        } else {
            result.pushObject(element);
        }
    });
    return result;
};

Which, when called somewhere in our code, results in the following assertion error:

Error: Assertion Failed: You attempted to access the `length` property (of <(unknown mixin):ember1475>).
Since Ember 3.1, this is usually fine as you no longer need to use `.get()`
to access computed properties. However, in this case, the object in question
is a special kind of Ember object (a proxy). Therefore, it is still necessary
to use `.get('length')` in this case.

If you encountered this error because of third-party code that you don't control,
there is more information at https://github.com/emberjs/ember.js/issues/16148, and
you can help us improve this error message by telling us more about what happened in
this situation.
    at new EmberError (error.js:40)
    at assert (index.js:146)
    at Object.get (core_object.js:57)
    at Object.isArray (utils.js:71)
    at prototype-extensions.js:28
    at Array.forEach (<anonymous>)
    at Array.Ember.A.flatten.Array.flatten (prototype-extensions.js:27)
    at prototype-extensions.js:29
    at Array.forEach (<anonymous>)
    at Array.Ember.A.flatten.Array.flatten (prototype-extensions.js:27)

Which blows up inside Ember itself, which I guess is a bug.

@rwjblue
Copy link
Member

rwjblue commented Apr 11, 2018

Switching from Ember.isArray to Array.isArray should resolve the issue I believe.

@boris-petrov
Copy link
Contributor Author

@rwjblue - yes, that fixed the issue in our case, thanks! But I believe that is a bug nonetheless.

@rwjblue
Copy link
Member

rwjblue commented Apr 12, 2018

It should be possible to ensure Ember.isArray does not trigger this error when probing for length.

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

2 participants