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(core) Better error messages for out of range numeric values #377

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions packages/concerto-core/lib/introspect/numbervalidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class NumberValidator extends Validator{
validate(identifier, value) {
if(value !== null) {
if(this.lowerBound !== null && value < this.lowerBound) {
this.reportError(identifier, 'Value is outside lower bound ' + value);
this.reportError(identifier, `Value ${value} is outside lower bound ${this.lowerBound}`);
}

if(this.upperBound !== null && value > this.upperBound) {
this.reportError(identifier, 'Value is outside upper bound ' + value);
this.reportError(identifier, `Value ${value} is outside upper bound ${this.upperBound}`);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/concerto-core/test/introspect/numbervalidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ describe('NumberValidator', () => {

(() => {
v.validate('id', -1);
}).should.throw(/org.acme.myField: Value is outside lower bound -1/);
}).should.throw(/org.acme.myField: Value -1 is outside lower bound 0/);
});

it('should detect upper bound violation', () => {
let v = new NumberValidator(mockField, VALID_UPPER_AND_LOWER_BOUND_AST);

(() => {
v.validate('id', 101);
}).should.throw(/org.acme.myField: Value is outside upper bound 101/);
}).should.throw(/org.acme.myField: Value 101 is outside upper bound 100/);
});

it('should ignore missing upper bound', () => {
Expand All @@ -103,7 +103,7 @@ describe('NumberValidator', () => {

(() => {
v.validate('id', -1);
}).should.throw(/org.acme.myField: Value is outside lower bound -1/);
}).should.throw(/org.acme.myField: Value -1 is outside lower bound 0/);
});

it('should ignore missing lower bound', () => {
Expand All @@ -112,7 +112,7 @@ describe('NumberValidator', () => {

(() => {
v.validate('id', 101);
}).should.throw(/org.acme.myField: Value is outside upper bound 101/);
}).should.throw(/org.acme.myField: Value 101 is outside upper bound 100/);
});

it('should do nothing if no value is given', () => {
Expand Down