From 583cb4048ae1193f0c0a770c9693e2d63709c745 Mon Sep 17 00:00:00 2001 From: anseki Date: Tue, 17 Mar 2015 12:11:46 +0900 Subject: [PATCH] Add more infomations to error object --- lib/read.cs.js | 2 +- lib/readline-sync.js | 8 ++++++-- package.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/read.cs.js b/lib/read.cs.js index a72872a..a8baa69 100644 --- a/lib/read.cs.js +++ b/lib/read.cs.js @@ -26,7 +26,7 @@ while (typeof(arg = args.shift()) === 'string') { } } -if (typeof(options.display) === 'string' && options.display !== '') { +if (typeof options.display === 'string' && options.display !== '') { ttyWrite(options.encoded ? decodeDOS(options.display) : options.display); } diff --git a/lib/readline-sync.js b/lib/readline-sync.js index 1ee40c5..97224a1 100644 --- a/lib/readline-sync.js +++ b/lib/readline-sync.js @@ -159,6 +159,9 @@ function _readlineShell(options) { res.error.command = SHELL_CMD; res.error.args = cmdArgs; res.error.shellMessage = e.stderr.trim(); + res.error.code = e.code; + res.error.signal = e.signal; + res.error.exitCode = e.status; } } else { res = _execSyncByFile(cmdArgs, execOptions); @@ -196,7 +199,7 @@ function _execSyncByFile(cmdArgs, execOptions) { return filepath; } - var execArgs, interpreter, res = {}, + var execArgs, interpreter, res = {}, exitCode, pathStdout = getTempfile('readline-sync.stdout'), pathStderr = getTempfile('readline-sync.stderr'), pathExit = getTempfile('readline-sync.exit'), @@ -243,7 +246,7 @@ function _execSyncByFile(cmdArgs, execOptions) { } while (fs.readFileSync(pathDone, {encoding: encoding}).trim() !== '1') {} - if (fs.readFileSync(pathExit, {encoding: encoding}).trim() === '0') { + if ((exitCode = fs.readFileSync(pathExit, {encoding: encoding}).trim()) === '0') { res.input = decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) + decipher.final(encoding); @@ -253,6 +256,7 @@ function _execSyncByFile(cmdArgs, execOptions) { res.error.command = SHELL_CMD; res.error.args = cmdArgs; res.error.shellMessage = fs.readFileSync(pathStderr, {encoding: encoding}).trim(); + res.error.exitCode = +exitCode; } fs.unlinkSync(pathStdout); diff --git a/package.json b/package.json index 8b02ded..bb4791d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "readline-sync", - "version": "0.7.8", + "version": "0.7.9", "title": "readlineSync", "description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).", "keywords": [