From bab562a44540f1da75c40957356890e1f0e0d9d3 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 28 Mar 2018 17:20:03 -0700 Subject: [PATCH 1/2] Fix missing logfile error handling not working --- src/emulator/logs.js | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/emulator/logs.js b/src/emulator/logs.js index ae757f2..23ff11e 100644 --- a/src/emulator/logs.js +++ b/src/emulator/logs.js @@ -20,37 +20,36 @@ const path = require('path'); const readline = require('readline'); function readLogLines (filePath, linesToRead, output) { - try { - const parts = path.parse(filePath); - const files = fs - .readdirSync(parts.dir) - .filter((file) => file && file.includes(parts.name)); - files.sort(); + const parts = path.parse(filePath); + const files = fs + .readdirSync(parts.dir) + .filter((file) => file && file.includes(parts.name)); + files.sort(); - // Here, we naively select the newest log file, even if the user wants to - // display more lines than are available in the newest log file. - const rl = readline.createInterface({ - input: fs.createReadStream(path.join(parts.dir, files[files.length - 1])), - terminal: false - }); - const lines = []; - rl - .on('line', (line) => { - lines.push(line); - }) - .on('close', () => { - lines - .slice(lines.length - linesToRead) - .forEach((line) => output(`${line}\n`)); - }); - } catch (err) { + // Here, we naively select the newest log file, even if the user wants to + // display more lines than are available in the newest log file. + const stream = fs.createReadStream(path.join(parts.dir, files[files.length - 1] || '')); + stream.on('error', (err) => { if (err.code === 'ENOENT') { output(''); return; } + }) - throw err; - } + const rl = readline.createInterface({ + input: stream, + terminal: false + }); + const lines = []; + rl + .on('line', (line) => { + lines.push(line); + }) + .on('close', () => { + lines + .slice(lines.length - linesToRead) + .forEach((line) => output(`${line}\n`)); + }); } module.exports = { From 50a7cb7444b85eaadec1918113ebc9f49c8bb59d Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Wed, 28 Mar 2018 17:30:58 -0700 Subject: [PATCH 2/2] Fix lint --- src/emulator/logs.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/emulator/logs.js b/src/emulator/logs.js index 23ff11e..a7b519b 100644 --- a/src/emulator/logs.js +++ b/src/emulator/logs.js @@ -32,9 +32,8 @@ function readLogLines (filePath, linesToRead, output) { stream.on('error', (err) => { if (err.code === 'ENOENT') { output(''); - return; } - }) + }); const rl = readline.createInterface({ input: stream,