Skip to content

Commit

Permalink
refactor(errors): improve error messages (#390)
Browse files Browse the repository at this point in the history
* refactor(errors): improve error messages

Signed-off-by: Stefan Blaginov <[email protected]>

* test(concerto): fix 6 failing tests

Signed-off-by: Stefan Blaginov <[email protected]>

Co-authored-by: Stefan Blaginov <[email protected]>
Co-authored-by: Matt Roberts <[email protected]>
  • Loading branch information
3 people authored Apr 1, 2022
1 parent 28252b7 commit 57afa8b
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 189 deletions.
8 changes: 4 additions & 4 deletions packages/concerto-cli/test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('cicero-cli', () => {
const result = await Commands.validate(input2, models, {offline:false});
JSON.parse(result).should.deep.equal(JSON.parse(inputText2));
} catch (err) {
err.message.should.equal('Instance org.accordproject.money.MonetaryAmount invalid enum value true for field CurrencyCode');
err.message.should.equal('Model violation in the "org.accordproject.money.MonetaryAmount" instance. Invalid enum value of "true" for the field "CurrencyCode".');
}
});

Expand All @@ -77,7 +77,7 @@ describe('cicero-cli', () => {
const result = await Commands.validate(input2, offlineModels, {offline:true});
JSON.parse(result).should.deep.equal(JSON.parse(inputText2));
} catch (err) {
err.message.should.equal('Instance org.accordproject.money.MonetaryAmount invalid enum value true for field CurrencyCode');
err.message.should.equal('Model violation in the "org.accordproject.money.MonetaryAmount" instance. Invalid enum value of "true" for the field "CurrencyCode".');
}
});

Expand Down Expand Up @@ -116,7 +116,7 @@ describe('cicero-cli', () => {
try {
await Commands.validate(input2, models, {offline:false, functional: true});
} catch (err) {
err.message.should.equal('Instance undefined invalid enum value true for field CurrencyCode');
err.message.should.equal('Model violation in the "undefined" instance. Invalid enum value of "true" for the field "CurrencyCode".');
}
});
});
Expand Down Expand Up @@ -258,4 +258,4 @@ describe('cicero-cli', () => {
output.cleanup();
});
});
});
});
96 changes: 48 additions & 48 deletions packages/concerto-core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,68 @@
"test-repeat-array": "{0} {0} {0}",
"test-repeat-object": "{value} {value} {value}",

"classdeclaration-constructor-modelastreq": "ModelFile and AST are required to create a ClassDecl.",
"classdeclaration-process-unrecmodelelem": "Unrecognised model element {type}",
"classdeclaration-getfield-notfindsupertype": "Could not find super type {type}",
"classdeclaration-validate-identifiernotproperty": "Class {class} is identified by field ({idField}) but does not contain this property.",
"classdeclaration-validate-identifiernotstring": "Class {class} is identified by field ({idField}) but the type of the field is not String.",
"classdeclaration-validate-duplicatefieldname": "Class {class} has more than one field named ({fieldName}).",
"classdeclaration-validate-missingidentifier" : "Class {class} is not declared as abstract. It must define an identifying field.",
"classdeclaration-constructor-modelastreq": "\"ModelFile\" and \"AST\" are required to create a \"ClassDecl\".",
"classdeclaration-process-unrecmodelelem": "Unrecognised model element \"{type}\".",
"classdeclaration-getfield-notfindsupertype": "Could not find supertype \"{type}\".",
"classdeclaration-validate-identifiernotproperty": "Class \"{class}\" is identified by field \"{idField}\", but does not contain this property.",
"classdeclaration-validate-identifiernotstring": "Class \"{class}\" is identified by field \"{idField}\", but the type of the field is not \"String\".",
"classdeclaration-validate-duplicatefieldname": "Class \"{class}\" has more than one field named \"{fieldName}\".",
"classdeclaration-validate-missingidentifier" : "Class \"{class}\" is not declared as \"abstract\". It must define an identifying field.",

"modelfile-constructor-unrecmodelelem": "Unrecognised model element {type}",
"modelfile-resolvetype-undecltype": "Undeclared type {type} in {context}",
"modelfile-resolveimport-failfindimp": "Failed to find {type} in list of imports [{imports}] for namespace {namespace}",
"modelfile-constructor-unrecmodelelem": "Unrecognised model element \"{type}\".",
"modelfile-resolvetype-undecltype": "Undeclared type \"{type}\" in \"{context}\".",
"modelfile-resolveimport-failfindimp": "Failed to find \"{type}\" in list of imports \"[{imports}]\" for namespace \"{namespace}\".",

"transactiondeclaration-getidentifierfieldname-noidentifyingfield": "Transactions do not have an identifying field.",

"composer-connect-noconopts": "connectOptions not specified",
"composer-connect-nokeyvalstore": "connectOptions.keyValStore not specified",
"composer-connect-nomembersrvcurl": "connectOptions.membershipServicesURL not specified",
"composer-connect-nopeerurl": "connectOptions.peerURL not specified",
"composer-connect-noeventhuburl": "connectOptions.eventHubURL not specified",
"composer-connect-notconnected": "Connection needs to be connected. Call connect(..)",
"composer-login-noenrollmentid": "enrollmentID not specified",
"composer-login-noenrollmentsecret": "enrollmentSecret not specified",
"composer-deploy-nosecuritycontext": "securityContext not specified",
"composer-connect-noconopts": "\"connectOptions\" not specified.",
"composer-connect-nokeyvalstore": "\"connectOptions.keyValStore\" not specified.",
"composer-connect-nomembersrvcurl": "\"connectOptions.membershipServicesURL\" not specified.",
"composer-connect-nopeerurl": "\"connectOptions.peerURL\" not specified.",
"composer-connect-noeventhuburl": "\"connectOptions.eventHubURL\" not specified.",
"composer-connect-notconnected": "Connection needs to be connected. Call \"connect(..)\".",
"composer-login-noenrollmentid": "\"enrollmentID\" not specified.",
"composer-login-noenrollmentsecret": "\"enrollmentSecret\" not specified.",
"composer-deploy-nosecuritycontext": "\"securityContext\" not specified.",

"factory-newinstance-missingidentifier": "Missing identifier for Type {type} in namespace {namespace}",
"factory-newinstance-invalididentifier": "Invalid or missing identifier for Type {type} in namespace {namespace}",
"factory-newinstance-abstracttype": "Cannot instantiate Abstract Type {type} in namespace {namespace}",
"factory-newrelationship-notregisteredwithmm" : "Cannot create relationship as namespace {namespace} is not known",
"factory-newinstance-typenotdeclaredinns" : "Cannot instantiate Type {type} in namespace {namespace}",
"factory-newinstance-missingidentifier": "Missing identifier for Type \"{type}\" in namespace \"{namespace}\".",
"factory-newinstance-invalididentifier": "Invalid or missing identifier for Type \"{type}\" in namespace \"{namespace}\".",
"factory-newinstance-abstracttype": "Cannot instantiate the abstract type \"{type}\" in the \"{namespace}\" namespace.",
"factory-newrelationship-notregisteredwithmm" : "Cannot create relationship as namespace \"{namespace}\" is not known.",
"factory-newinstance-typenotdeclaredinns" : "Cannot instantiate Type \"{type}\" in namespace \"{namespace}\".",

"instancegenerator-newinstance-noconcreteclass": "No concrete extending type for {type}",
"instancegenerator-newinstance-noconcreteclass": "No concrete extending type for \"{type}\".",

"modelmanager-resolvetype-nonsfortype": "No registered namespace for type {type} in {context}",
"modelmanager-resolvetype-notypeinnsforcontext": "No type {type} in namespace {namespace} for {context}",
"modelmanager-resolvetype-nonsfortype": "No registered namespace for type \"{type}\" in \"{context}\".",
"modelmanager-resolvetype-notypeinnsforcontext": "No type \"{type}\" in namespace \"{namespace}\" for \"{context}\".",

"modelmanager-gettype-noregisteredns": "Namespace is not defined for type {type}",
"modelmanager-gettype-notypeinns": "Type {type} is not defined in namespace {namespace}",
"modelmanager-gettype-noregisteredns": "Namespace is not defined for type \"{type}\".",
"modelmanager-gettype-notypeinns": "Type \"{type}\" is not defined in namespace \"{namespace}\".",

"serializer-constructor-factorynull": "Factory cannot be null",
"serializer-constructor-modelmanagernull": "ModelManager cannot be null",
"serializer-tojson-notcobject": "Serializer.toJSON only accepts Concept, Event, Asset, Participant or Transaction.",
"serializer-constructor-factorynull": "\"Factory\" cannot be \"null\".",
"serializer-constructor-modelmanagernull": "\"ModelManager\" cannot be \"null\".",
"serializer-tojson-notcobject": "\"Serializer.toJSON\" only accepts \"Concept\", \"Event\", \"Asset\", \"Participant\" or \"Transaction\".",

"util-securitycheck-novalidcontext": "A valid SecurityContext must be specified.",
"util-securitycheck-novalidcontext": "A valid \"SecurityContext\" must be specified.",

"modelutil-getnamespace-nofnq": "FQN is invalid.",

"resourcevalidator-notresourceorconcept": "Model violation in instance {resourceId} class {classFQN} has value {invalidValue} expected a Resource or a Concept.",
"resourcevalidator-notrelationship": "Model violation in instance {resourceId} class {classFQN} has value {invalidValue} expected a Relationship.",
"resourcevalidator-fieldtypeviolation": "Model violation in instance {resourceId} field {propertyName} has value {value} ({typeOfValue}) expected type {fieldType}",
"resourcevalidator-missingrequiredproperty": "Instance {resourceId} missing required field {fieldName}",
"resourcevalidator-invalidenumvalue": "Instance {resourceId} invalid enum value {value} for field {fieldName}",
"resourcevalidator-abstractclass": "The class {className} is abstract. Should not have an instance!",
"resourcevalidator-undeclaredfield": "Instance {resourceId} has a property named {propertyName} which is not declared in {fullyQualifiedTypeName}",
"resourcevalidator-invalidfieldassignment": "Instance {resourceId} has property {propertyName} with type {objectType} that is not derived from {fieldType}",
"resourcevalidator-emptyidentifier": "Instance {resourceId} has an empty identifier.",
"resourcevalidator-notresourceorconcept": "Model violation in the \"{resourceId}\" instance. Class \"{classFQN}\" has the value of \"{invalidValue}\". Expected a \"Resource\" or a \"Concept\".",
"resourcevalidator-notrelationship": "Model violation in the \"{resourceId}\" instance. Class \"{classFQN}\" has a value of \"{invalidValue}\". Expected a \"Relationship\".",
"resourcevalidator-fieldtypeviolation": "Model violation in the \"{resourceId}\" instance. The field \"{propertyName}\" has a value of \"{value}\" (type of value: \"{typeOfValue}\"). Expected type of value: \"{fieldType}\".",
"resourcevalidator-missingrequiredproperty": "The instance \"{resourceId}\" is missing the required field \"{fieldName}\".",
"resourcevalidator-invalidenumvalue": "Model violation in the \"{resourceId}\" instance. Invalid enum value of \"{value}\" for the field \"{fieldName}\".",
"resourcevalidator-abstractclass": "The class \"{className}\" is abstract and should not contain an instance.",
"resourcevalidator-undeclaredfield": "Instance \"{resourceId}\" has a property named \"{propertyName}\", which is not declared in \"{fullyQualifiedTypeName}\".",
"resourcevalidator-invalidfieldassignment": "Instance \"{resourceId}\" has a property \"{propertyName}\" with type \"{objectType}\" that is not derived from \"{fieldType}\".",
"resourcevalidator-emptyidentifier": "Instance \"{resourceId}\" has an empty identifier.",

"typenotfounderror-defaultmessage": "Type not found: {typeName}",
"typenotfounderror-defaultmessage": "Type \"{typeName}\" not found.",

"whereastvalidator-propertytypeviolation": "Property {propertyName} cannot be compared with {value} ({typeOfValue}) expected type {fieldType}",
"whereastvalidator-enum-propertytypeviolation": "Enum property {propertyName} cannot be compared with {value} ({typeOfValue}) expected a String",
"whereastvalidator-relationship-propertytypeviolation": "Relationship {propertyName} cannot be compared with {value} ({typeOfValue}) expected type String",
"whereastvalidator-unsupportedtype": "Property {propertyName} of type {fieldType} cannot be compared with a literal value.",
"whereastvalidator-invalidoperator": "Property {propertyName} cannot be compared using the {operator} operator."
"whereastvalidator-propertytypeviolation": "Property \"{propertyName}\" cannot be compared with \"{value}\" (type of value: \"{typeOfValue}\"). Expected type: \"{fieldType}\".",
"whereastvalidator-enum-propertytypeviolation": "Enum property \"{propertyName}\" cannot be compared with \"{value}\" (type of value: \"{typeOfValue}\"). Expected type: \"String\".",
"whereastvalidator-relationship-propertytypeviolation": "Relationship \"{propertyName}\" cannot be compared with \"{value}\" (type of value: \"{typeOfValue}\"). Expected type: \"String\".",
"whereastvalidator-unsupportedtype": "Property \"{propertyName}\" of type \"{fieldType}\" cannot be compared with a literal value.",
"whereastvalidator-invalidoperator": "Property \"{propertyName}\" cannot be compared using the \"{operator}\" operator."
}
}
6 changes: 3 additions & 3 deletions packages/concerto-core/test/1.0.0/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ const negative = [{
sample: './data/hierarchy2err.json',
ctoFiles: ['./models/hierarchy2.cto'],
error: 'Unexpected properties for type org.test.C: c, t',
errorFunctional: 'Instance undefined has a property named c which is not declared in org.test.C'
errorFunctional: 'Instance "undefined" has a property named "c", which is not declared in "org.test.C".'
}, {
name: 'user defined identifier',
sample: './data/identifier1err.json',
ctoFiles: ['./models/identifier1.cto'],
error: 'Invalid or missing identifier for Type A1 in namespace org.test',
errorFunctional: 'Instance org.test.A1#undefined has an empty identifier.',
error: 'Invalid or missing identifier for Type "A1" in namespace "org.test".',
errorFunctional: 'Instance "org.test.A1#undefined" has an empty identifier.',
}];

describe('Validation (1.0.0)', () => {
Expand Down
Loading

0 comments on commit 57afa8b

Please sign in to comment.