Skip to content

Commit

Permalink
Merge pull request #3570 from HeroicEric/update-ember-deprecate-and-w…
Browse files Browse the repository at this point in the history
…arn-calls

Update `Ember.deprecate` and `Ember.warn` calls to include required information
  • Loading branch information
bmac committed Jul 27, 2015
2 parents 9c83224 + 5ba8df8 commit d842890
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/ember-data/lib/adapters/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ AdapterError.prototype = Object.create(EmberError.prototype);
*/
export function InvalidError(errors) {
if (!Ember.isArray(errors)) {
Ember.deprecate('`InvalidError` expects json-api formatted errors.');
Ember.deprecate('`InvalidError` expects json-api formatted errors.', false, { id: 'ds.errors.invalid-error-expects-json-api-format', until: '2.0.0' });
errors = errorsHashToArray(errors);
}
AdapterError.call(this, errors, 'The adapter rejected the commit because it was invalid');
Expand Down
5 changes: 4 additions & 1 deletion packages/ember-data/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ var _FixtureAdapter = FixtureAdapter;
Object.defineProperty(DS, 'FixtureAdapter', {
get: function() {
if (_FixtureAdapter === FixtureAdapter) {
Ember.deprecate('DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master');
Ember.deprecate('DS.FixtureAdapter has been deprecated and moved into an unsupported addon: https://github.com/emberjs/ember-data-fixture-adapter/tree/master', false, {
id: 'ds.adapter.fixture-adapter-deprecated',
until: '2.0.0'
});
}
return _FixtureAdapter;
},
Expand Down
9 changes: 5 additions & 4 deletions packages/ember-data/lib/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,11 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
key = this.keyForAttribute(attr, 'serialize');
hasMany = snapshot.hasMany(attr);

Ember.warn("The embedded relationship '" + key + "' is undefined for '" +
snapshot.modelName +
"' with id '" + snapshot.id +
"'. Please include it in your original payload.", Ember.typeOf(hasMany) !== 'undefined');
Ember.warn(
`The embedded relationship '${key}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`,
Ember.typeOf(hasMany) !== 'undefined',
{ id: 'ds.serializer.embedded-relationship-undefined' }
);

json[key] = Ember.A(hasMany).map((embeddedSnapshot) => {
var embeddedJson = embeddedSnapshot.record.serialize({ includeId: true });
Expand Down
8 changes: 6 additions & 2 deletions packages/ember-data/lib/serializers/rest-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ var RESTSerializer = JSONSerializer.extend({

var typeName = this.modelNameFromPayloadKey(modelName);
if (!store.modelFactoryFor(typeName)) {
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false);
Ember.warn(this.warnMessageNoModelForKey(modelName, typeName), false, {
id: 'ds.serializer.model-for-key-missing'
});
continue;
}

Expand Down Expand Up @@ -334,7 +336,9 @@ var RESTSerializer = JSONSerializer.extend({
for (var prop in payload) {
var modelName = this.modelNameFromPayloadKey(prop);
if (!store.modelFactoryFor(modelName)) {
Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false);
Ember.warn(this.warnMessageNoModelForKey(prop, modelName), false, {
id: 'ds.serializer.model-for-key-missing'
});
continue;
}
var type = store.modelFor(modelName);
Expand Down
6 changes: 4 additions & 2 deletions packages/ember-data/lib/system/container-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ ContainerProxy.prototype.registerAlias = function(source, dest, preLookup) {

ContainerProxy.prototype.registerDeprecation = function(deprecated, valid) {
var preLookupCallback = function() {
Ember.deprecate("You tried to look up '" + deprecated + "', " +
"but this has been deprecated in favor of '" + valid + "'.", false);
Ember.deprecate(`You tried to look up '${deprecated}', but this has been deprecated in favor of '${valid}'.`, false, {
id: 'ds.store.deprecated-lookup',
until: '2.0.0'
});
};

return this.registerAlias(deprecated, valid, preLookupCallback);
Expand Down
13 changes: 11 additions & 2 deletions packages/ember-data/lib/system/relationships/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,17 @@ function belongsTo(modelName, options) {

return Ember.computed({
get: function(key) {
Ember.warn('You provided a serialize option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.Serializer and it\'s implementations http://emberjs.com/api/data/classes/DS.Serializer.html', !opts.hasOwnProperty('serialize'));
Ember.warn('You provided an embedded option on the "' + key + '" property in the "' + this._internalModel.modelName + '" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html', !opts.hasOwnProperty('embedded'));
if (opts.hasOwnProperty('serialize')) {
Ember.warn(`You provided a serialize option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.Serializer and it's implementations http://emberjs.com/api/data/classes/DS.Serializer.html`, false, {
id: 'ds.model.serialize-option-in-belongs-to'
});
}

if (opts.hasOwnProperty('embedded')) {
Ember.warn(`You provided an embedded option on the "${key}" property in the "${this._internalModel.modelName}" class, this belongs in the serializer. See DS.EmbeddedRecordsMixin http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html`, false, {
id: 'ds.model.embedded-option-in-belongs-to'
});
}

return this._internalModel._relationships.get(key).getRecord();
},
Expand Down
8 changes: 6 additions & 2 deletions packages/ember-data/lib/system/relationships/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ Model.reopenClass({

var inverseName, inverseKind, inverse;

Ember.warn("Detected a reflexive relationship by the name of '" + name + "' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.", options.inverse || propertyMeta.type !== propertyMeta.parentType.modelName);

//If inverse is specified manually, return the inverse
if (options.inverse) {
inverseName = options.inverse;
Expand All @@ -256,6 +254,12 @@ Model.reopenClass({
inverseKind = inverse.kind;
} else {
//No inverse was specified manually, we need to use a heuristic to guess one
if (propertyMeta.type === propertyMeta.parentType.modelName) {
Ember.warn(`Detected a reflexive relationship by the name of '${name}' without an inverse option. Look at http://emberjs.com/guides/models/defining-models/#toc_reflexive-relation for how to explicitly specify inverses.`, false, {
id: 'ds.model.reflexive-relationship-without-inverse'
});
}

var possibleRelationships = findPossibleInverses(this, inverseType);

if (possibleRelationships.length === 0) { return null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ Relationship.prototype = {
},

updateLink: function(link) {
Ember.warn("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the association is not an async relationship.", this.isAsync);
Ember.warn(`You have pushed a record of type '${this.record.type.modelName}' with '${this.key}' as a link, but the association is not an async relationship.`, this.isAsync, {
id: 'ds.store.push-link-for-sync-relationship'
});
Ember.assert("You have pushed a record of type '" + this.record.type.modelName + "' with '" + this.key + "' as a link, but the value of that link is not a string.", typeof link === 'string' || link === null);
if (link !== this.link) {
this.link = link;
Expand Down
30 changes: 16 additions & 14 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,9 @@ Store = Service.extend({
resolvedRecords = Ember.A(resolvedRecords);
var missingRecords = requestedRecords.reject((record) => resolvedRecords.contains(record));
if (missingRecords.length) {
Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false);
Ember.warn('Ember Data expected to find records with the following ids in the adapter response but they were missing: ' + Ember.inspect(Ember.A(missingRecords).mapBy('id')), false, {
id: 'ds.store.missing-records-from-adapter'
});
}
rejectRecords(missingRecords);
};
Expand Down Expand Up @@ -1168,7 +1170,9 @@ Store = Service.extend({

if (!Ember.ENV.ENABLE_DS_FILTER) {
Ember.deprecate('The filter API will be moved into a plugin soon. To enable store.filter using an environment flag, or to use an alternative, you can visit the ember-data-filter addon page', false, {
url: 'https://github.com/ember-data/ember-data-filter'
url: 'https://github.com/ember-data/ember-data-filter',
id: 'ds.store.filter-deprecated',
until: '2.0.0'
});
}

Expand Down Expand Up @@ -1584,8 +1588,6 @@ Store = Service.extend({
updated.
*/
push: function(data) {
Ember.assert("Expected an object as `data` in a call to `push` but was " + Ember.typeOf(data), Ember.typeOf(data) === 'object');

if (data.included) {
data.included.forEach((recordData) => this._pushInternalModel(recordData));
}
Expand Down Expand Up @@ -1622,7 +1624,8 @@ Store = Service.extend({
})) + ". Make sure they've been defined in your model.",
Object.keys(data).filter((key) => {
return !(key === 'id' || key === 'links' || get(type, 'fields').has(key) || key.match(/Type$/));
}).length === 0
}).length === 0,
{ id: 'ds.store.unknown-keys-in-payload' }
);
}

Expand Down Expand Up @@ -1839,12 +1842,11 @@ Store = Service.extend({
adapterFor: function(modelOrClass) {
var modelName;

Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, typeof modelOrClass === 'string');

if (typeof modelOrClass !== 'string') {
modelName = modelOrClass.modelName;
} else {
if (typeof modelOrClass === 'string') {
modelName = modelOrClass;
} else {
Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, false, { id: 'ds.store.passing-classes-deprecated', until: '2.0.0' });
modelName = modelOrClass.modelName;
}

return this.lookupAdapter(modelName);
Expand Down Expand Up @@ -1882,11 +1884,11 @@ Store = Service.extend({
serializerFor: function(modelOrClass) {
var modelName;

Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelOrClass)}`, typeof modelOrClass === 'string');
if (typeof modelOrClass !== 'string') {
modelName = modelOrClass.modelName;
} else {
if (typeof modelOrClass === 'string') {
modelName = modelOrClass;
} else {
Ember.deprecate(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${Ember.inspect(modelName)}`, false, { id: 'ds.store.passing-classes-deprecated', until: '2.0.0' });
modelName = modelOrClass.modelName;
}

var fallbacks = [
Expand Down

0 comments on commit d842890

Please sign in to comment.