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 <[email protected]>
  • Loading branch information
Santanu Roy committed Dec 28, 2023
1 parent e70eb40 commit 846fff2
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 51 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 ,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
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
};
22 changes: 22 additions & 0 deletions packages/concerto-util/lib/errorcodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 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_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 };
2 changes: 2 additions & 0 deletions packages/concerto-util/types/lib/errorcodes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEFAULT_VALIDATOR_EXCEPTION: "DefaultValidatorException";
export const REGEX_VALIDATOR_EXCEPTION: "RegexValidatorException";

0 comments on commit 846fff2

Please sign in to comment.