concerto
concerto copied to clipboard
Throw error on validation of model with decorators with type reference if type not present
Bug Report 🐛
Currently if we add decorator with type reference, it does not check if the type exists within the namespace. We should be throwing error if the type is not imported or not present within the namespace
namespace [email protected]
import [email protected].{Color}
concept Owner {
o String ownerName
}
// should throw error on model validation as Train is not present in namespace
@colorOptions(Train)
concept CarColor {}
Might have to fix this issue first https://github.com/accordproject/concerto/issues/797
Expected Behavior
Should throw error on validation
Current Behavior
Possible Solution
Steps to Reproduce
- Add the above model to model manager and validate, will not throw error
Detailed Description
Possible Implementation
Hey @sanketshevkar is this the correct file to be changed? https://github.com/accordproject/concerto/blob/ed6c188d4a03dbc5252a691b51087ad050ee1705/packages/concerto-core/lib/introspect/decorator.js#L33-L45
Hey @sanketshevkar is this the correct file to be changed?
Yes!
Before you start you might want to look at #797, it's an issue connected to the issue. @subhajit20
Hi @sanketshevkar , I've worked on it by throwning exceptions on not-found types in proccess method like Here is the updated Proccess
process() {
this.name = this.ast.name;
this.arguments = [];
if (this.ast.arguments) {
for (let n = 0; n < this.ast.arguments.length; n++) {
let thing = this.ast.arguments[n];
if (thing) {
if (thing.$class === `${MetaModelNamespace}.DecoratorTypeReference`) {
// XXX Is this really what we want?
if (!MetaModelNamespace[thing.type.name]) {
const errorMessage = `Type '${thing.type.name}' not found within the namespace '${MetaModelNamespace}'.`;
throw new IllegalModelException(errorMessage);
}
this.arguments.push({
type: 'Identifier',
name: thing.type.name,
array: thing.isArray
});
} else {
this.arguments.push(thing.value);
}
}
}
}
}
- Am I going to the right Direction or you want something Else?
- And Assign me this Issue please
Hey @sanketshevkar , I've Created a PR of My changes, I hope to get a Feedback