From d15498715dbdbbd90f8cdcf6a99ecbf769982f78 Mon Sep 17 00:00:00 2001 From: gap Date: Fri, 15 Jun 2018 09:10:07 -0400 Subject: [PATCH] Improve debugging support When this error is encountered in the field, I see it via honeybadger, but I have none of the context about what unit it was called in, and what unit it was being converted to. Help the debugging by adding some info to the exception. I'm not entirely sure that 'toString' is what I want here - perhaps others in the community can help make that the right expression? --- src/type/unit/Unit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/type/unit/Unit.js b/src/type/unit/Unit.js index c98e358fd..be28160c4 100644 --- a/src/type/unit/Unit.js +++ b/src/type/unit/Unit.js @@ -801,7 +801,7 @@ function factory (type, config, load, typed, math) { // other = new Unit(null, valuelessUnit) other = Unit.parse(valuelessUnit) if (!this.equalBase(other)) { - throw new Error('Units do not match') + throw new Error(`Units do not match ('${other.toString()}' != '${this.toString()}')`) } if (other.value !== null) { throw new Error('Cannot convert to a unit with a value') @@ -813,7 +813,7 @@ function factory (type, config, load, typed, math) { return other } else if (type.isUnit(valuelessUnit)) { if (!this.equalBase(valuelessUnit)) { - throw new Error('Units do not match') + throw new Error(`Units do not match ('${valuelessUnit.toString()}' != '${this.toString()}')`) } if (valuelessUnit.value !== null) { throw new Error('Cannot convert to a unit with a value')