Skip to content

Commit

Permalink
feat(error): addressed PR comments and restructured the code
Browse files Browse the repository at this point in the history
Signed-off-by: Santanu Roy <edu.santanu12@gmail.com>
Signed-off-by: Santanu Roy <santanu.roy@docusign.com>
  • Loading branch information
Santanu Roy committed Dec 28, 2023
1 parent 3b6180a commit 6fce3db
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 61 deletions.
3 changes: 0 additions & 3 deletions packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,6 @@ class ScalarDeclaration extends Declaration {
+ boolean isEvent()
+ boolean isConcept()
}
class StringValidatorException extends Error {
+ void constructor(string,string)
}
class TransactionDeclaration extends IdentifiedDeclaration {
+ void constructor(ModelFile,Object) throws IllegalModelException
+ string declarationKind()
Expand Down
4 changes: 2 additions & 2 deletions packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 3.13.3 {1df986a8e13fe0d984069b9637c0a1c4} 2023-11-07
Version 3.13.3 {b286dfdeeb654d25be7c5f9cc6305e38} 2023-11-07
- Added DCS and vocabulary extraction support for decoratorManager
- Added StringValidatorException class to support error type
- Added errortype to BaseException and used that to define error types in introspect

Version 3.13.2 {dccc690753912cf87e7ceec56d949058} 2023-10-18
- Add getNamespace method to key type and value type of maps
Expand Down
3 changes: 2 additions & 1 deletion packages/concerto-core/lib/introspect/stringvalidator.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 { isNull } = require('../util');
const Validator = require('./validator');

Expand Down Expand Up @@ -70,7 +71,7 @@ class StringValidator extends Validator{
this.regex = new CustomRegExp(validator.pattern, validator.flags);
}
catch(exception) {
this.reportError(field.getName(), exception.message,'RegexValidatorException');
this.reportError(field.getName(), exception.message,ErrorCodes.REGEX_VALIDATOR_EXCEPTION);
}
}
}
Expand Down
38 changes: 0 additions & 38 deletions packages/concerto-core/lib/introspect/stringvalidatorexception.js

This file was deleted.

7 changes: 3 additions & 4 deletions packages/concerto-core/lib/introspect/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

'use strict';

const StringValidatorException = require('./stringvalidatorexception');

const { BaseException, ErrorCodes } = require('@accordproject/concerto-util');
// Types needed for TypeScript generation.
/* eslint-disable no-unused-vars */
/* istanbul ignore next */
Expand Down Expand Up @@ -51,8 +50,8 @@ class Validator {
* @param {string} errorType the type of error
* @throws {Error} throws an error to report the message
*/
reportError(id, msg, errorType='ValidatorError') {
throw new StringValidatorException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg ,errorType);
reportError(id, msg, errorType=ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION) {
throw new BaseException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg ,undefined,errorType);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/concerto-core/types/lib/introspect/validator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ declare class Validator {
/**
* @param {string} id the identifier of the instance
* @param {string} msg the exception message
* @param {string} errorType the type of error
* @throws {Error} throws an error to report the message
*/
reportError(id: string, msg: string): void;
reportError(id: string, msg: string, errorType?: string): void;
/**
* Visitor design pattern
* @param {Object} visitor - the visitor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ 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;
8 changes: 0 additions & 8 deletions packages/concerto-core/types/lib/typenotfoundexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ export = TypeNotFoundException;
* @memberof module:concerto-core
*/
declare class TypeNotFoundException extends BaseException {
/**
* Constructor. If the optional 'message' argument is not supplied, it will be set to a default value that
* includes the type name.
* @param {string} typeName - fully qualified type name.
* @param {string|undefined} message - error message.
* @param {string} component - the optional component which throws this error
*/
constructor(typeName: string, message: string | undefined, component: string);
typeName: string;
/**
* Get the name of the type that was not found.
Expand Down
6 changes: 5 additions & 1 deletion packages/concerto-util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const Label = require('./lib/label');
// Identifiers
const Identifiers = require('./lib/identifiers');

//errorcodes
const ErrorCodes = require('./lib/errorcodes');

module.exports = {
BaseException,
BaseFileException,
Expand All @@ -67,5 +70,6 @@ module.exports = {
Logger,
TypedStack,
Label,
Identifiers
Identifiers,
ErrorCodes
};
7 changes: 6 additions & 1 deletion packages/concerto-util/lib/baseexception.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

'use strict';



const packageJson = require('../package.json');
const ErrorCodes = require('./errorcodes');

/**
* A base class for all Concerto exceptions
Expand All @@ -27,12 +30,14 @@ 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
*/
constructor(message, component) {
constructor(message, component, errorType) {
super(message);
this.component = component || packageJson.name;
this.name = this.constructor.name;
this.message = message;
this.errorType = errorType || ErrorCodes.DEFAULT_BASE_EXCEPTION;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
}
Expand Down
24 changes: 24 additions & 0 deletions packages/concerto-util/lib/errorcodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

//default base exception
const DEFAULT_BASE_EXCEPTION = 'DefaultBaseException';
//default validator exception which is being used when there is no specified validator exception in introspect
const DEFAULT_VALIDATOR_EXCEPTION = 'DefaultValidatorException';
// exception code for regex validator format error
const REGEX_VALIDATOR_EXCEPTION = 'RegexValidatorException';

module.exports = {DEFAULT_BASE_EXCEPTION, DEFAULT_VALIDATOR_EXCEPTION, REGEX_VALIDATOR_EXCEPTION};
3 changes: 2 additions & 1 deletion packages/concerto-util/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ import Logger = require("./lib/logger");
import TypedStack = require("./lib/typedstack");
import Label = require("./lib/label");
import Identifiers = require("./lib/identifiers");
export { BaseException, BaseFileException, FileDownloader, CompositeFileLoader, DefaultFileLoader, GitHubFileLoader, HTTPFileLoader, Writer, FileWriter, InMemoryWriter, ModelWriter, Logger, TypedStack, Label, Identifiers };
import ErrorCodes = require("./lib/errorcodes");
export { BaseException, BaseFileException, FileDownloader, CompositeFileLoader, DefaultFileLoader, GitHubFileLoader, HTTPFileLoader, Writer, FileWriter, InMemoryWriter, ModelWriter, Logger, TypedStack, Label, Identifiers, ErrorCodes };
4 changes: 3 additions & 1 deletion packages/concerto-util/types/lib/baseexception.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ 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
*/
constructor(message: string, component: string);
constructor(message: string, component: string, errorType: string);
component: any;
errorType: string;
}
3 changes: 3 additions & 0 deletions packages/concerto-util/types/lib/errorcodes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const DEFAULT_BASE_EXCEPTION: "DefaultBaseException";
export const DEFAULT_VALIDATOR_EXCEPTION: "DefaultValidatorException";
export const REGEX_VALIDATOR_EXCEPTION: "RegexValidatorException";

0 comments on commit 6fce3db

Please sign in to comment.