Skip to content

Commit

Permalink
fix(core) Better error messages for out of range numeric values
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
Jerome Simeon authored and jeromesimeon committed Feb 1, 2022
1 parent b3a1acb commit a691df3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
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

0 comments on commit a691df3

Please sign in to comment.