diff --git a/lib/CliUx.js b/lib/CliUx.js index b4d7565ad..80881d86e 100644 --- a/lib/CliUx.js +++ b/lib/CliUx.js @@ -35,6 +35,26 @@ UX.miniDisplay = function(list) { }; +var safe_push = function() { + var argv = arguments; + var table = argv[0]; + + for (var i = 1; i < argv.length; ++i) { + var elem = argv[i]; + if (elem[Object.keys(elem)[0]] === undefined + || elem[Object.keys(elem)[0]] === null) { + elem[Object.keys(elem)[0]] = 'N/A'; + } + else if (Array.isArray(elem[Object.keys(elem)[0]])) { + elem[Object.keys(elem)[0]].forEach(function(curr, j) { + if (curr === undefined || curr === null) + elem[Object.keys(elem)[0]][j] = 'N/A'; + }); + } + table.push(elem); + } +}; + /** * Description * @method describeTable @@ -57,19 +77,6 @@ UX.describeTable = function(process) { throw new Error(pm2_env.created_at + ' is not a valid date: '+e.message, e.fileName, e.lineNumber); } - var safe_push = function() { - var argv = arguments; - var table = argv[0]; - - for (var i = 1; i < argv.length; ++i) { - var elem = argv[i]; - if (elem[Object.keys(elem)[0]] === undefined - || elem[Object.keys(elem)[0]] === null) - elem[Object.keys(elem)[0]] = 'N/A'; - table.push(elem); - } - }; - console.log('Describing process with id %d - name %s', pm2_env.pm_id, pm2_env.name); safe_push(table, { 'status' : colorStatus(pm2_env.status) }, @@ -125,7 +132,7 @@ UX.describeTable = function(process) { var obj = {}; var value = pm2_env.axm_monitor[key].value || pm2_env.axm_monitor[key]; obj[key] = value; - table_probes.push(obj); + safe_push(table_probes, obj); }); console.log(table_probes.toString()); @@ -172,7 +179,8 @@ UX.dispAsTable = function(list, interact_infos) { l.monit.cpu + '%', l.monit ? UX.bytesToSize(l.monit.memory, 3) : '' ]; - module_table.push(obj); + safe_push(module_table, obj); + //module_table.push(obj); } else { obj[key] = [ @@ -185,7 +193,8 @@ UX.dispAsTable = function(list, interact_infos) { l.monit ? UX.bytesToSize(l.monit.memory, 3) : '', l.pm2_env.watch ? chalk.green.bold('enabled') : chalk.grey('disabled') ]; - app_table.push(obj); + safe_push(app_table, obj); + //app_table.push(obj); } });