From bf918bd016f645b9d307e4314943f787082b8627 Mon Sep 17 00:00:00 2001 From: James Holding Date: Sun, 25 Oct 2015 10:14:00 +0000 Subject: [PATCH] Upgrade script fails on some consoles The upgrade script errors/fails on some consoles if the stdout.columns isn't set (my console did this when upgrading a Docker instance of NodeBB). Checking for stdout.columns before using, falling back to a couple of spaces for slightly prettiness if we can't work out the console width. --- nodebb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodebb b/nodebb index db9dcbe425..01aa843a18 100755 --- a/nodebb +++ b/nodebb @@ -144,8 +144,10 @@ switch(process.argv[2]) { if (err) { process.stdout.write('\nError'.red + ': ' + err.message + '\n'); } else { - var message = 'NodeBB Upgrade Complete!', - spaces = new Array(Math.floor(process.stdout.columns / 2) - (message.length / 2) + 1).join(' '); + var message = 'NodeBB Upgrade Complete!'; + // some consoles will return undefined/zero columns, so just use 2 spaces in upgrade script if we can't get our column count + var columns = process.stdout.columns; + var spaces = columns ? new Array(Math.floor(columns / 2) - (message.length / 2) + 1).join(' ') : " "; process.stdout.write('OK\n'.green); process.stdout.write('\n' + spaces + message.green.bold + '\n\n'.reset);