From 22560b6ebc7b78f72d7063ff99b17b1021d76de1 Mon Sep 17 00:00:00 2001 From: samreid Date: Tue, 24 Sep 2019 08:31:24 -0600 Subject: [PATCH] Improve error handling and docs, see https://github.com/phetsims/chipper/issues/786 --- js/common/ChipperStringUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/common/ChipperStringUtils.js b/js/common/ChipperStringUtils.js index 89848b626..e4f0abe68 100644 --- a/js/common/ChipperStringUtils.js +++ b/js/common/ChipperStringUtils.js @@ -168,6 +168,9 @@ if ( result.value === undefined ) { throw new Error( `no value for string: ${key}` ); } + if ( typeof result.value !== 'string' ) { + throw new Error( `value should be a string for key ${key}` ); + } return result.value; } @@ -176,8 +179,7 @@ }, /** - * Call a function on each string object in a string map. Recursively dive into each object that doesn't have a - * `value` to find nested string objects too. + * Call a function on each object with a value attribute in an object tree. * @param {Object.} map - string map, like a loaded JSON strings file * @param {function(key:string, {value:string})} func * @public