concerto icon indicating copy to clipboard operation
concerto copied to clipboard

Throw error on validation of model with decorators with type reference if type not present

Open sanketshevkar opened this issue 1 year ago • 5 comments

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

  1. Add the above model to model manager and validate, will not throw error

Detailed Description

Possible Implementation

sanketshevkar avatar Feb 01 '24 10:02 sanketshevkar

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

subhajit20 avatar Feb 26 '24 15:02 subhajit20

Hey @sanketshevkar is this the correct file to be changed?

Yes!

sanketshevkar avatar Feb 28 '24 05:02 sanketshevkar

Before you start you might want to look at #797, it's an issue connected to the issue. @subhajit20

sanketshevkar avatar Feb 28 '24 05:02 sanketshevkar

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

ahmad-kashkoush avatar Mar 05 '24 19:03 ahmad-kashkoush

Hey @sanketshevkar , I've Created a PR of My changes, I hope to get a Feedback

ahmad-kashkoush avatar Mar 05 '24 20:03 ahmad-kashkoush