Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(error): adding type to error in string validator in introspect #773

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat(error): resolved pr comments
Signed-off-by: Santanu Roy <edu.santanu12@gmail.com>
santanu8961 committed Dec 29, 2023
commit 18bd20f4d7f90de2e62a76a4a21d63456895afc1
2 changes: 1 addition & 1 deletion packages/concerto-core/api.txt
Original file line number Diff line number Diff line change
@@ -344,6 +344,6 @@ class Serializer {
+ Resource fromJSON(Object,Object?,boolean,boolean,number?)
}
class TypeNotFoundException extends BaseException {
+ void constructor(string,string|,string)
+ void constructor(string,string|,string,string)
+ string getTypeName()
}
2 changes: 1 addition & 1 deletion packages/concerto-core/changelog.txt
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
# Note that the latest public API is documented using JSDocs and is available in api.txt.
#

Version 3.13.3 {b286dfdeeb654d25be7c5f9cc6305e38} 2023-11-07
Version 3.13.3 {8f59b43e6071c4d3ae42e94476142f7a} 2023-11-07
- Added DCS and vocabulary extraction support for decoratorManager
- Added errortype to BaseException and used that to define error types in introspect

2 changes: 1 addition & 1 deletion packages/concerto-core/lib/introspect/stringvalidator.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 1 addition & 1 deletion packages/concerto-core/lib/introspect/validator.js
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ class Validator {
* @throws {Error} throws an error to report the message
*/
reportError(id, msg, errorType=ErrorCodes.DEFAULT_VALIDATOR_EXCEPTION) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I have used error codes as constants instead of inline strings for consistency

throw new BaseException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg ,undefined,errorType);
throw new BaseException('Validator error for field `' + id + '`. ' + this.getFieldOrScalarDeclaration().getFullyQualifiedName() + ': ' + msg, undefined, errorType);
}

/**
7 changes: 4 additions & 3 deletions packages/concerto-core/lib/typenotfoundexception.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

'use strict';

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

/**
@@ -31,16 +31,17 @@ class TypeNotFoundException extends BaseException {
* @param {string} typeName - fully qualified type name.
* @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
*/
constructor(typeName, message, component) {
constructor(typeName, message, component, errorType = ErrorCodes.TYPE_NOT_FOUND_EXCEPTION) {
if (!message) {
const formatter = Globalize.messageFormatter('typenotfounderror-defaultmessage');
message = formatter({
typeName: typeName
});
}

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

9 changes: 9 additions & 0 deletions packages/concerto-core/types/lib/typenotfoundexception.d.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,15 @@ 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
* @param {string} errorType - the error code related to the error
*/
constructor(typeName: string, message: string | undefined, component: string, errorType?: string);
typeName: string;
/**
* Get the name of the type that was not found.
4 changes: 3 additions & 1 deletion packages/concerto-util/lib/errorcodes.js
Original file line number Diff line number Diff line change
@@ -20,5 +20,7 @@ const DEFAULT_BASE_EXCEPTION = 'DefaultBaseException';
const DEFAULT_VALIDATOR_EXCEPTION = 'DefaultValidatorException';
// exception code for regex validator format error
const REGEX_VALIDATOR_EXCEPTION = 'RegexValidatorException';
// base exception for Type not found
const TYPE_NOT_FOUND_EXCEPTION = 'TypeNotFoundException';

module.exports = {DEFAULT_BASE_EXCEPTION, DEFAULT_VALIDATOR_EXCEPTION, REGEX_VALIDATOR_EXCEPTION};
module.exports = {DEFAULT_BASE_EXCEPTION, DEFAULT_VALIDATOR_EXCEPTION, REGEX_VALIDATOR_EXCEPTION, TYPE_NOT_FOUND_EXCEPTION};
1 change: 1 addition & 0 deletions packages/concerto-util/types/lib/errorcodes.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const DEFAULT_BASE_EXCEPTION: "DefaultBaseException";
export const DEFAULT_VALIDATOR_EXCEPTION: "DefaultValidatorException";
export const REGEX_VALIDATOR_EXCEPTION: "RegexValidatorException";
export const TYPE_NOT_FOUND_EXCEPTION: "TypeNotFoundException";