Skip to content

Commit 848fa32

Browse files
committed
improve error message
1 parent 8f7e3f3 commit 848fa32

File tree

2 files changed

+75
-22
lines changed

2 files changed

+75
-22
lines changed

src/log.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ exports.invalidClassName = function invalidClassName(
200200
* @description Missing a property
201201
*/
202202
exports.missingProperty = function missingProperty(propertyName) {
203-
getLogger().warn("missing property '" + propertyName + "'");
203+
getLogger().warn(
204+
"missing property '" + propertyName + "' for a schema or a model"
205+
);
204206
};
205207

206208
/**
@@ -236,11 +238,7 @@ exports.invalidTypeImp = function invalidTypeImp(property, className) {
236238
*/
237239
exports.missingPropertyImp = function missingPropertyImp(property, className) {
238240
getLogger().warn(
239-
"missing property '" +
240-
property +
241-
"' for the definition of '" +
242-
className +
243-
"'"
241+
"missing property '" + property + "' in the model '" + className + "'"
244242
);
245243
};
246244

@@ -614,7 +612,7 @@ exports.behaviorNotUnique = function behaviorNotUnique(id, stateName) {
614612
*/
615613
exports.invalidStateOn = function invalidStateOn(id, stateName) {
616614
getLogger().warn(
617-
"try to add a behavior with an unkwown state '" +
615+
"try to add a behavior to an unkwown state '" +
618616
stateName +
619617
"' on class '" +
620618
id +
@@ -715,7 +713,7 @@ exports.invalidChannelEvent = function invalidChannelEvent(
715713
* @param {String} id id of the component
716714
* @param {String} className class name of the component
717715
* @param {String} methodName name of the component
718-
* @description invalid parameter number for an action add with on method
716+
* @description invalid parameter number for a behavior add with 'on' method
719717
*/
720718
exports.invalidParamNumberMethodOn = function invalidParamNumberMethodOn(
721719
id,
@@ -728,7 +726,7 @@ exports.invalidParamNumberMethodOn = function invalidParamNumberMethodOn(
728726
classInfo = " (class '" + className + "')";
729727
}
730728
getLogger().warn(
731-
"invalid number of parameters when adding an action on method '" +
729+
"invalid number of parameters when adding a behavior on method '" +
732730
methodName +
733731
"' on component '" +
734732
id +
@@ -781,7 +779,11 @@ exports.invalidUseOfComponent = function invalidUseOfComponent(id) {
781779
* @description Try to add an invalid schema
782780
*/
783781
exports.invalidSchema = function invalidSchema(name) {
784-
getLogger().warn("the schema '" + name + "' is not valid");
782+
getLogger().warn(
783+
"the schema '" +
784+
name +
785+
"' is not valid, it has been removed from the metamodel"
786+
);
785787
};
786788

787789
/**
@@ -790,7 +792,11 @@ exports.invalidSchema = function invalidSchema(name) {
790792
* @description Try to add an invalid model
791793
*/
792794
exports.invalidModel = function invalidModel(name) {
793-
getLogger().warn("the model '" + name + "' is not valid");
795+
getLogger().warn(
796+
"the model '" +
797+
name +
798+
"' is not valid, it has been removed from the metamodel"
799+
);
794800
};
795801

796802
/**
@@ -1031,6 +1037,25 @@ exports.actionInvokeError = function actionInvokeError(
10311037
}
10321038
};
10331039

1040+
/**
1041+
* @method invalidSchemaPropertyName
1042+
* @param {String} name name of the schema
1043+
* @param {String} propName name of the property
1044+
* @description Invalid name for the property of a schema
1045+
*/
1046+
exports.invalidSchemaPropertyName = function invalidSchemaPropertyName(
1047+
name,
1048+
propName
1049+
) {
1050+
getLogger().warn(
1051+
"invalid name '" +
1052+
propName +
1053+
"' for schema '" +
1054+
name +
1055+
"': a name do not begin with '_'"
1056+
);
1057+
};
1058+
10341059
/**
10351060
* @method invalidSchemaProperty
10361061
* @param {String} name name of the schema

src/metamodel.js

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ var PROPERTY_TYPE = 'property';
5252
var LINK_TYPE = 'link';
5353
var COLLECTION_TYPE = 'collection';
5454
var internalTypes = ['property', 'collection', 'link', 'method', 'event'];
55+
var internalNames = [
56+
'_id',
57+
'_name',
58+
'_inherit',
59+
'_description',
60+
'_class',
61+
'_core'
62+
];
5563
var defaultTypes = [
5664
'boolean',
5765
'string',
@@ -76,6 +84,21 @@ var store = {
7684

7785
/* Private methods */
7886

87+
/**
88+
* @method isInternalName
89+
* @param {String} name
90+
* @private
91+
* @description is name an internal name
92+
*/
93+
function isInternalName(name) {
94+
var result = true;
95+
96+
if (internalNames.indexOf(name) === -1) {
97+
result = false;
98+
}
99+
return result;
100+
}
101+
79102
/**
80103
* @method generateModels
81104
* @private
@@ -129,6 +152,13 @@ function generateModels() {
129152
model._description = schema._description;
130153
}
131154

155+
// check valid name
156+
for (att in schema) {
157+
if (!isInternalName(att) && att.indexOf('_') === 0) {
158+
$log.invalidSchemaPropertyName(schema._name, att);
159+
}
160+
}
161+
132162
// set model default values
133163
for (att in schema) {
134164
switch (true) {
@@ -188,7 +218,7 @@ function generateModels() {
188218
};
189219
break;
190220
default:
191-
if (att.indexOf('_') !== 0) {
221+
if (!isInternalName(att)) {
192222
$log.invalidSchemaProperty(schema._name, att);
193223
}
194224
break;
@@ -1070,18 +1100,17 @@ function merge(source, target, all) {
10701100

10711101
/**
10721102
* @method schema
1073-
* @param {JSON} importedSchema schema to add
1074-
* @description Add a new schema
1103+
* @param {JSON} schema schema
1104+
* @description Add a new schema to the metamodel
10751105
*/
1076-
exports.schema = function schema(importedSchema) {
1106+
exports.schema = function schema(schema) {
10771107
var id = null;
10781108
var result = [];
1079-
var schema = null;
10801109
var name = '';
10811110
var mergedSchema = {};
10821111
var schemas = [];
10831112

1084-
schema = JSON.parse(JSON.stringify(importedSchema));
1113+
schema = JSON.parse(JSON.stringify(schema));
10851114
name = schema[NAME];
10861115

10871116
if (typeof schema[ID] === 'undefined') {
@@ -1141,19 +1170,18 @@ exports.schema = function schema(importedSchema) {
11411170

11421171
/**
11431172
* @method model
1144-
* @param {JSON} importedModel model to add
1145-
* @description Add a new model
1173+
* @param {JSON} model model
1174+
* @description Add a new model to the metamodel
11461175
*/
1147-
exports.model = function model(importedModel) {
1148-
var model = null;
1176+
exports.model = function model(model) {
11491177
var id = null;
11501178
var result = [];
11511179
var inherit = '';
11521180
var name = '';
11531181
var mergedModel = {};
11541182
var models = [];
11551183

1156-
model = JSON.parse(JSON.stringify(importedModel));
1184+
model = JSON.parse(JSON.stringify(model));
11571185
name = model[NAME];
11581186

11591187
if (typeof model[ID] === 'undefined') {

0 commit comments

Comments
 (0)