Skip to content

Better Library Errors #365

Open
Open

Description

@narkeeso

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions