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

Better Library Errors #365

Open
narkeeso opened this issue May 10, 2014 · 0 comments
Open

Better Library Errors #365

narkeeso opened this issue May 10, 2014 · 0 comments

Comments

@narkeeso
Copy link
Contributor

I've been working heavily ember-model (store-less version) for the past 6-8 months and have learned a great deal. I thought that it might be good to find points where ember-model might fail due to user error.

For example I constantly run into issues with HasManyEmbedded objects where I am incorrectly setting properties on a model and the model fails to materialize. The most common error I see with ember-model is:

Uncaught TypeError: Cannot read property 'reference' of undefined 

It's when the model is attempting to materialize:

Ember.EmbeddedHasManyArray = Ember.ManyArray.extend({
  materializeRecord: function(idx) {
    var klass = get(this, 'modelClass'),
        primaryKey = get(klass, 'primaryKey'),
        content = get(this, 'content'),
        reference = content.objectAt(idx),
        attrs;

    if (reference !== undefined) {
      attrs = reference.data;
    } else {
      throw new Error('There was a problem with materializeRecord() on ' +
        klass);
    }

    if (reference.record) {
      return reference.record;
    } else {
      var record = klass.create({ _reference: reference });
      reference.record = record;
      if (attrs) {
        record.load(attrs[primaryKey], attrs);
      }
      return record;
    }
  },
});

Above I added a check on the reference and to throw an error with the model with an issue so I know exactly where to start looking. Is this the best way to go about better informing the user?

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

No branches or pull requests

1 participant