Add more infomations to error object

This commit is contained in:
anseki 2015-03-17 12:11:46 +09:00
parent c984c1b7be
commit 583cb4048a
3 changed files with 8 additions and 4 deletions

View file

@ -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); ttyWrite(options.encoded ? decodeDOS(options.display) : options.display);
} }

View file

@ -159,6 +159,9 @@ function _readlineShell(options) {
res.error.command = SHELL_CMD; res.error.command = SHELL_CMD;
res.error.args = cmdArgs; res.error.args = cmdArgs;
res.error.shellMessage = e.stderr.trim(); res.error.shellMessage = e.stderr.trim();
res.error.code = e.code;
res.error.signal = e.signal;
res.error.exitCode = e.status;
} }
} else { } else {
res = _execSyncByFile(cmdArgs, execOptions); res = _execSyncByFile(cmdArgs, execOptions);
@ -196,7 +199,7 @@ function _execSyncByFile(cmdArgs, execOptions) {
return filepath; return filepath;
} }
var execArgs, interpreter, res = {}, var execArgs, interpreter, res = {}, exitCode,
pathStdout = getTempfile('readline-sync.stdout'), pathStdout = getTempfile('readline-sync.stdout'),
pathStderr = getTempfile('readline-sync.stderr'), pathStderr = getTempfile('readline-sync.stderr'),
pathExit = getTempfile('readline-sync.exit'), pathExit = getTempfile('readline-sync.exit'),
@ -243,7 +246,7 @@ function _execSyncByFile(cmdArgs, execOptions) {
} }
while (fs.readFileSync(pathDone, {encoding: encoding}).trim() !== '1') {} 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 = res.input =
decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) + decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) +
decipher.final(encoding); decipher.final(encoding);
@ -253,6 +256,7 @@ function _execSyncByFile(cmdArgs, execOptions) {
res.error.command = SHELL_CMD; res.error.command = SHELL_CMD;
res.error.args = cmdArgs; res.error.args = cmdArgs;
res.error.shellMessage = fs.readFileSync(pathStderr, {encoding: encoding}).trim(); res.error.shellMessage = fs.readFileSync(pathStderr, {encoding: encoding}).trim();
res.error.exitCode = +exitCode;
} }
fs.unlinkSync(pathStdout); fs.unlinkSync(pathStdout);

View file

@ -1,6 +1,6 @@
{ {
"name": "readline-sync", "name": "readline-sync",
"version": "0.7.8", "version": "0.7.9",
"title": "readlineSync", "title": "readlineSync",
"description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).", "description": "Synchronous Readline for interactively running to have a conversation with the user via a console(TTY).",
"keywords": [ "keywords": [