From 81fc6e0e4175c9b2fba1c9939dfbdbd91e13a113 Mon Sep 17 00:00:00 2001 From: YangYong3 Date: Wed, 8 Mar 2017 13:11:53 +0900 Subject: [PATCH 1/2] joyent/node-triton#89 -o field,field,...` should be strict about allowed fields --- lib/tabula.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/tabula.js b/lib/tabula.js index ccaf13f..ea2c73c 100644 --- a/lib/tabula.js +++ b/lib/tabula.js @@ -208,6 +208,8 @@ function tabulaFormat(items, options) { assert.optionalArrayOfString(options.validFields, 'options.validFields'); assert.optionalBool(options.dottedLookup, 'options.dottedLookup'); assert.optionalBool(options.noAnsi, 'options.noAnsi'); + assert.optionalBool(options.caseInsensitiveLookup, + 'options.caseInsensitiveLookup'); if (!options.columns && items.length === 0) { return ''; @@ -287,7 +289,10 @@ function tabulaFormat(items, options) { if (options.dottedLookup) { try { cell = dottedLookup(o, col.lookup); - } catch (e) {} + } catch (e) { + if (options.caseInsensitiveLookup) + throw new Error(e); + } } else { cell = o[col.lookup]; } @@ -403,8 +408,14 @@ function dottedLookup(obj, str, c) { for (var i = 0; i < dots.length; i++) { var dot = dots[i]; s.push(dot); - if (!o.hasOwnProperty(dot)) - throw new Error('no property ' + s.join(c) + ' found'); + if (!o.hasOwnProperty(dot)) { + var msg = 'no property ' + s.join(c) + ' found' + '\n'; + msg += 'The following properties are supported :' + '\n\n'; + Object.keys(o).forEach(function (k) { + msg += k + '\n'; + }); + throw new Error(msg); + } o = o[dot]; } return o; From 51c1c1e62f7600db5c07d1fbe834abfc69cc86c3 Mon Sep 17 00:00:00 2001 From: YangYong3 Date: Fri, 10 Mar 2017 14:00:57 +0900 Subject: [PATCH 2/2] don`t need new Excetion --- lib/tabula.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tabula.js b/lib/tabula.js index ea2c73c..a9bebeb 100644 --- a/lib/tabula.js +++ b/lib/tabula.js @@ -291,7 +291,7 @@ function tabulaFormat(items, options) { cell = dottedLookup(o, col.lookup); } catch (e) { if (options.caseInsensitiveLookup) - throw new Error(e); + throw e; } } else { cell = o[col.lookup];