From a691df34decd8aa5fcfe0ff2bdc049a9936c60d4 Mon Sep 17 00:00:00 2001 From: Jerome Simeon Date: Mon, 24 Jan 2022 10:38:09 -0500 Subject: [PATCH] fix(core) Better error messages for out of range numeric values Signed-off-by: Jerome Simeon --- packages/concerto-core/lib/introspect/numbervalidator.js | 4 ++-- packages/concerto-core/test/introspect/numbervalidator.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/concerto-core/lib/introspect/numbervalidator.js b/packages/concerto-core/lib/introspect/numbervalidator.js index 0f21bb8506..7946a87612 100644 --- a/packages/concerto-core/lib/introspect/numbervalidator.js +++ b/packages/concerto-core/lib/introspect/numbervalidator.js @@ -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}`); } } } diff --git a/packages/concerto-core/test/introspect/numbervalidator.js b/packages/concerto-core/test/introspect/numbervalidator.js index 29ecbb0073..382770d88e 100644 --- a/packages/concerto-core/test/introspect/numbervalidator.js +++ b/packages/concerto-core/test/introspect/numbervalidator.js @@ -86,7 +86,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 detect upper bound violation', () => { @@ -94,7 +94,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 ignore missing upper bound', () => { @@ -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', () => { @@ -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', () => {