From eef6a929de2c2aaacfcfbcd3fb200eecd6b7e2ac Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 13 May 2018 13:05:30 -0600 Subject: [PATCH] handle undefined, log warning --- index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 22c64fb..19ac5c3 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var fs = require('fs'); var sfs = require('safe-replace').create(); function snakeCase(key) { + // TODO let user supply list of exceptions if ('tlsSni01Port' === key) { return 'tls_sni_01_port'; } @@ -92,7 +93,7 @@ function toPyVal(val) { if (-1 === val.indexOf(',')) { val += ','; // disambguates value from array with one element } - return val; + return val; } return val && JSON.stringify(val); @@ -116,6 +117,12 @@ function stringifyPythonConf(obj, cb) { var num = obj.__keys[key]; var comment = ''; + if ('undefined' === typeof pyval) { + if ('number' === typeof num) { + obj.__lines[num] = "___DELETE_ME___"; + } + return; + } if ('number' !== typeof num) { obj.__lines.push(pykey + ' = ' + pyval); @@ -127,6 +134,12 @@ function stringifyPythonConf(obj, cb) { return; } + if (!obj.__lines[num] || !obj.__lines[num].indexOf) { + console.warn('[pyconf] WARN index past array length:'); + console.log(obj.__lines.length, num, obj.__lines[num]); + return; + } + // restore comments if (-1 !== obj.__lines[num].indexOf('#')) { comment = obj.__lines[num].replace(/.*?(\s*#.*)/, '$1');