Skip to content

Commit

Permalink
feat: added status and code to errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kailash Kejriwal <[email protected]>
  • Loading branch information
kailash360 committed Mar 3, 2024
1 parent ed6c188 commit b10f7ff
Show file tree
Hide file tree
Showing 21 changed files with 12,944 additions and 4,365 deletions.
17,102 changes: 12,786 additions & 4,316 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class IdentifiedDeclaration extends ClassDeclaration {
+ void constructor(ModelFile,Object) throws IllegalModelException
}
class IllegalModelException extends BaseFileException {
+ void constructor(string,ModelFile?,Object?,number,number,number,number,string?)
+ void constructor(string,ModelFile?,Object?,number,number,number,number,string?,string?,string?)
}
class Introspector {
+ void constructor(ModelManager)
Expand Down Expand Up @@ -285,7 +285,7 @@ class TransactionDeclaration extends IdentifiedDeclaration {
+ string declarationKind()
}
class MetamodelException extends BaseException {
+ void constructor(string)
+ void constructor(string,string?,string?)
}
class Identifiable extends Typed {
~ void constructor(ModelManager,ClassDeclaration,string,string,string,string)
Expand Down Expand Up @@ -335,7 +335,7 @@ class ModelManager extends BaseModelManager {
}
+ object getRootModel()
class SecurityException extends BaseException {
+ void constructor(string)
+ void constructor(string,string?,string?)
}
class Serializer {
+ void constructor(Factory,ModelManager,object?)
Expand All @@ -344,6 +344,6 @@ class Serializer {
+ Resource fromJSON(Object,Object?,boolean,boolean,number?)
}
class TypeNotFoundException extends BaseException {
+ void constructor(string,string|,string,string)
+ void constructor(string,string|,string,string,string?)
+ string getTypeName()
}
10 changes: 8 additions & 2 deletions packages/concerto-core/lib/introspect/illegalmodelexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

'use strict';

const { ErrorCodes } = require('@accordproject/concerto-util');
const { BaseFileException } = require('@accordproject/concerto-util');

// Types needed for TypeScript generation.
Expand Down Expand Up @@ -42,8 +43,10 @@ class IllegalModelException extends BaseFileException {
* @param {number} fileLocation.end.line - end line of the error location.
* @param {number} fileLocation.end.column - end column of the error location.
* @param {string} [component] - the component which throws this error
* @param {string} [code] - the optional code of the error
* @param {string} [status] - the optional status of the error
*/
constructor(message, modelFile, fileLocation, component) {
constructor(message, modelFile, fileLocation, component, code, status) {

let messageSuffix = '';
let fileName = null;
Expand All @@ -61,7 +64,10 @@ class IllegalModelException extends BaseFileException {
// First character to be uppercase
messageSuffix = messageSuffix.charAt(0).toUpperCase() + messageSuffix.slice(1);

super(message, fileLocation, message + ' ' + messageSuffix, fileName, component);
code = code || ErrorCodes.ILLEGAL_MODEL_EXCEPTION.code;
status = status || ErrorCodes.ILLEGAL_MODEL_EXCEPTION.status;

super(message, fileLocation, message + ' ' + messageSuffix, fileName, component,code, status);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/lib/introspect/stringvalidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class StringValidator extends Validator{
this.regex = new CustomRegExp(validator.pattern, validator.flags);
}
catch(exception) {
this.reportError(field.getName(), exception.message, ErrorCodes.REGEX_VALIDATOR_EXCEPTION);
this.reportError(field.getName(), exception.message, ErrorCodes.REGEX_VALIDATOR_EXCEPTION.code, ErrorCodes.REGEX_VALIDATOR_EXCEPTION.status);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/concerto-core/lib/introspect/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class Validator {
/**
* @param {string} id the identifier of the instance
* @param {string} msg the exception message
* @param {string} errorType the type of error
* @param {string} [errorType] the type of error
* @param {string} [errorStatus] the status of error
* @throws {Error} throws an error to report the message
*/
reportError(id, msg, errorType=ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION) {
throw new BaseException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg, undefined, errorType);
reportError(id, msg, errorType=ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION.code, errorStatus=ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION.status) {
throw new BaseException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg, undefined, errorType,errorStatus);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions packages/concerto-core/lib/metamodelexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const { BaseException } = require('@accordproject/concerto-util');
const { BaseException, ErrorCodes } = require('@accordproject/concerto-util');

/**
* Class representing an invalid Metamodel instance (JSON AST)
Expand All @@ -27,9 +27,13 @@ class MetamodelException extends BaseException {
/**
* Create the MetamodelException.
* @param {string} message - The exception message.
* @param {string} [code] - the optional code of the error
* @param {string} [status] - the optional status of the error
*/
constructor(message) {
super(message);
constructor(message, code, status) {
code = code || ErrorCodes.METAMODEL_EXCEPTION.code;
status = status || ErrorCodes.METAMODEL_EXCEPTION.status;
super(message,'',code, status);
}

}
Expand Down
10 changes: 7 additions & 3 deletions packages/concerto-core/lib/securityexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const { BaseException } = require('@accordproject/concerto-util');
const { BaseException, ErrorCodes } = require('@accordproject/concerto-util');

/**
* Class representing a security exception
Expand All @@ -27,9 +27,13 @@ class SecurityException extends BaseException {
/**
* Create the SecurityException.
* @param {string} message - The exception message.
* @param {string} [status] - the optional status of the error
* @param {string} [code] - the optional code of the error
*/
constructor(message) {
super(message);
constructor(message, status, code) {
status = status || ErrorCodes.SECURITY_EXCEPTION.status;
code = code || ErrorCodes.SECURITY_EXCEPTION.code;
super(message, '', '', status, code);
}

}
Expand Down
10 changes: 8 additions & 2 deletions packages/concerto-core/lib/serializer/validationexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

'use strict';

const { ErrorCodes } = require('@accordproject/concerto-util');

const BaseException = require('@accordproject/concerto-util').BaseException;

/**
Expand All @@ -30,9 +32,13 @@ class ValidationException extends BaseException {
* Create a ValidationException
* @param {string} message - the message for the exception
* @param {string} component - the optional component which throws this error
* @param {string} [code] - the optional code of the error
* @param {string} [status] - the optional status of the error
*/
constructor(message, component) {
super(message, component);
constructor(message, component,code, status) {
code = code || ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION.code;
status = status || ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION.status;
super(message, component, code, status);
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/concerto-core/lib/typenotfoundexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ class TypeNotFoundException extends BaseException {
* @param {string|undefined} message - error message.
* @param {string} component - the optional component which throws this error
* @param {string} errorType - the error code related to the error
* @param {string} [status] - the error status related to the error
*/
constructor(typeName, message, component, errorType = ErrorCodes.TYPE_NOT_FOUND_EXCEPTION) {
constructor(typeName, message, component, errorType = ErrorCodes.TYPE_NOT_FOUND_EXCEPTION.code, status = ErrorCodes.TYPE_NOT_FOUND_EXCEPTION.status ) {
if (!message) {
const formatter = Globalize.messageFormatter('typenotfounderror-defaultmessage');
message = formatter({
typeName: typeName
});
}

super(message, component, errorType);
super(message, component, errorType, status);
this.typeName = typeName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ declare class IllegalModelException extends BaseFileException {
* @param {number} fileLocation.end.line - end line of the error location.
* @param {number} fileLocation.end.column - end column of the error location.
* @param {string} [component] - the component which throws this error
* @param {string} [code] - the optional code of the error
* @param {string} [status] - the optional status of the error
*/
constructor(message: string, modelFile?: ModelFile, fileLocation?: any, component?: string);
constructor(message: string, modelFile?: ModelFile, fileLocation?: any, component?: string, code?: string, status?: string);
}
import { BaseFileException } from "@accordproject/concerto-util";
import ModelFile = require("./modelfile");
5 changes: 3 additions & 2 deletions packages/concerto-core/types/lib/introspect/validator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ declare class Validator {
/**
* @param {string} id the identifier of the instance
* @param {string} msg the exception message
* @param {string} errorType the type of error
* @param {string} [errorType] the type of error
* @param {string} [errorStatus] the status of error
* @throws {Error} throws an error to report the message
*/
reportError(id: string, msg: string, errorType?: string): void;
reportError(id: string, msg: string, errorType?: string, errorStatus?: string): void;
/**
* Visitor design pattern
* @param {Object} visitor - the visitor
Expand Down
4 changes: 3 additions & 1 deletion packages/concerto-core/types/lib/metamodelexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ declare class MetamodelException extends BaseException {
/**
* Create the MetamodelException.
* @param {string} message - The exception message.
* @param {string} [code] - the optional code of the error
* @param {string} [status] - the optional status of the error
*/
constructor(message: string);
constructor(message: string, code?: string, status?: string);
}
import { BaseException } from "@accordproject/concerto-util";
4 changes: 3 additions & 1 deletion packages/concerto-core/types/lib/securityexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ declare class SecurityException extends BaseException {
/**
* Create the SecurityException.
* @param {string} message - The exception message.
* @param {string} [status] - the optional status of the error
* @param {string} [code] - the optional code of the error
*/
constructor(message: string);
constructor(message: string, status?: string, code?: string);
}
import { BaseException } from "@accordproject/concerto-util";
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export = ValidationException;
* @private
*/
declare class ValidationException extends BaseException {
/**
* Create a ValidationException
* @param {string} message - the message for the exception
* @param {string} component - the optional component which throws this error
*/
constructor(message: string, component: string);
}
import BaseException_1 = require("@accordproject/concerto-util/types/lib/baseexception");
import BaseException = BaseException_1.BaseException;
3 changes: 2 additions & 1 deletion packages/concerto-core/types/lib/typenotfoundexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ declare class TypeNotFoundException extends BaseException {
* @param {string|undefined} message - error message.
* @param {string} component - the optional component which throws this error
* @param {string} errorType - the error code related to the error
* @param {string} [status] - the error status related to the error
*/
constructor(typeName: string, message: string | undefined, component: string, errorType?: string);
constructor(typeName: string, message: string | undefined, component: string, errorType?: string, status?: string);
typeName: string;
/**
* Get the name of the type that was not found.
Expand Down
8 changes: 5 additions & 3 deletions packages/concerto-util/lib/baseexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ class BaseException extends Error {
* Create the BaseException.
* @param {string} message - The exception message.
* @param {string} component - The optional component which throws this error.
* @param {string} errorType - The optional error code regarding the error
* @param {string} [errorCode] - The optional error code regarding the error
* @param {string} [errorStatus] - The optional error status regarding the error
*/
constructor(message, component, errorType) {
constructor(message, component, errorCode, errorStatus) {
super(message);
this.component = component || packageJson.name;
this.name = this.constructor.name;
this.message = message;
this.errorType = errorType || ErrorCodes.DEFAULT_BASE_EXCEPTION;
this.code = errorCode || ErrorCodes.DEFAULT_BASE_EXCEPTION.code;
this.status = errorStatus || ErrorCodes.DEFAULT_BASE_EXCEPTION.status;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/concerto-util/lib/basefileexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
'use strict';

const BaseException = require('./baseexception');
const ErrorCodes = require('./errorcodes');

/**
* Exception throws when a Concerto file is semantically invalid
Expand All @@ -31,12 +32,16 @@ class BaseFileException extends BaseException {
* @param {string} fullMessage - the optional full message text
* @param {string} [fileName] - the file name
* @param {string} [component] - the component which throws this error
* @param {string} [code] - the optional code regarding the error
* @param {string} [status] - the optional status regarding the error
*/
constructor(message, fileLocation, fullMessage, fileName, component) {
constructor(message, fileLocation, fullMessage, fileName, component, code, status) {
super(fullMessage ? fullMessage : message, component);
this.fileLocation = fileLocation;
this.shortMessage = message;
this.fileName = fileName;
this.code = code || ErrorCodes.DEFAULT_BASE_EXCEPTION.code,
this.status = status || ErrorCodes.DEFAULT_BASE_EXCEPTION.status;
}

/**
Expand Down
42 changes: 37 additions & 5 deletions packages/concerto-util/lib/errorcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,44 @@
'use strict';

//default base exception
const DEFAULT_BASE_EXCEPTION = 'DefaultBaseException';
const DEFAULT_BASE_EXCEPTION = {
status: '1',
code: 'DefaultBaseException'
};
//default validator exception which is being used when there is no specified validator exception in introspect
const DEFAULT_VALIDATOR_EXCEPTION = 'DefaultValidatorException';
const DEFAULT_VALIDATOR_EXCEPTION = {
status:'2',
code: 'DefaultValidatorException'
};
// exception code for regex validator format error
const REGEX_VALIDATOR_EXCEPTION = 'RegexValidatorException';
const REGEX_VALIDATOR_EXCEPTION = {
status:'3',
code:'RegexValidatorException'
};
// base exception for Type not found
const TYPE_NOT_FOUND_EXCEPTION = 'TypeNotFoundException';
const TYPE_NOT_FOUND_EXCEPTION = {
status:'4',
code:'TypeNotFoundException'
};
// semanic exception in Concerto
const CONCERTO_SEMANTIC_EXCEPTION = {
status:'5',
code: 'InvalidSemanticException'
};
// security exception in Concerto
const SECURITY_EXCEPTION = {
status:'6',
code:'SecurityException'
};
// Invalid Metamodel Exception
const METAMODEL_EXCEPTION = {
status:'7',
code:'InvalidMetamodelException'
};
// Illegal Model Exception
const ILLEGAL_MODEL_EXCEPTION = {
status:'8',
code:'IllegalModelException'
};

module.exports = {DEFAULT_BASE_EXCEPTION, DEFAULT_VALIDATOR_EXCEPTION, REGEX_VALIDATOR_EXCEPTION, TYPE_NOT_FOUND_EXCEPTION};
module.exports = {DEFAULT_BASE_EXCEPTION, DEFAULT_VALIDATOR_EXCEPTION, REGEX_VALIDATOR_EXCEPTION, TYPE_NOT_FOUND_EXCEPTION,CONCERTO_SEMANTIC_EXCEPTION, SECURITY_EXCEPTION, METAMODEL_EXCEPTION,ILLEGAL_MODEL_EXCEPTION};
8 changes: 5 additions & 3 deletions packages/concerto-util/types/lib/baseexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ declare class BaseException extends Error {
* Create the BaseException.
* @param {string} message - The exception message.
* @param {string} component - The optional component which throws this error.
* @param {string} errorType - The optional error code regarding the error
* @param {string} [errorCode] - The optional error code regarding the error
* @param {string} [errorStatus] - The optional error status regarding the error
*/
constructor(message: string, component: string, errorType: string);
constructor(message: string, component: string, errorCode?: string, errorStatus?: string);
component: any;
errorType: string;
code: string;
status: string;
}
4 changes: 3 additions & 1 deletion packages/concerto-util/types/lib/basefileexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ declare class BaseFileException extends BaseException {
* @param {string} fullMessage - the optional full message text
* @param {string} [fileName] - the file name
* @param {string} [component] - the component which throws this error
* @param {string} [code] - the optional code regarding the error
* @param {string} [status] - the optional status regarding the error
*/
constructor(message: string, fileLocation: string, fullMessage: string, fileName?: string, component?: string);
constructor(message: string, fileLocation: string, fullMessage: string, fileName?: string, component?: string, code?: string, status?: string);
fileLocation: string;
shortMessage: string;
fileName: string;
Expand Down
Loading

0 comments on commit b10f7ff

Please sign in to comment.