From 51de362938ae1d310340ccf72d2bf702c96644ca Mon Sep 17 00:00:00 2001 From: Jessie France Date: Thu, 24 Jun 2021 14:12:59 -0600 Subject: [PATCH 1/3] feat: expose error code --- README.md | 5 +++++ shell.js | 3 +++ src/errorCode.js | 10 ++++++++++ 3 files changed, 18 insertions(+) create mode 100644 src/errorCode.js diff --git a/README.md b/README.md index 74b3df953..b3ad3e2a7 100644 --- a/README.md +++ b/README.md @@ -742,6 +742,11 @@ return value to be an error message. If you need the last error message, use the `.stderr` attribute from the last command's return value instead. +### errorCode() + +Returns the error code from the last command. + + ### ShellString(str) Examples: diff --git a/shell.js b/shell.js index e4c1c5df1..acc770325 100644 --- a/shell.js +++ b/shell.js @@ -34,6 +34,9 @@ exports.exit = process.exit; //@include ./src/error.js exports.error = require('./src/error'); +//@include ./src/errorCode.js +exports.errorCode = require('./src/errorCode'); + //@include ./src/common.js exports.ShellString = common.ShellString; diff --git a/src/errorCode.js b/src/errorCode.js new file mode 100644 index 000000000..a1c7fd23f --- /dev/null +++ b/src/errorCode.js @@ -0,0 +1,10 @@ +var common = require('./common'); + +//@ +//@ ### errorCode() +//@ +//@ Returns the error code from the last command. +function errorCode() { + return common.state.errorCode; +} +module.exports = errorCode; From f4c96433e7e4beb7f21f95efcacda8c5fd719685 Mon Sep 17 00:00:00 2001 From: Jessie France Date: Thu, 24 Jun 2021 14:13:49 -0600 Subject: [PATCH 2/3] use errorCode() in a test --- test/grep.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/grep.js b/test/grep.js index 8f6a0c6a8..d5e696cad 100644 --- a/test/grep.js +++ b/test/grep.js @@ -24,6 +24,7 @@ test('no args', t => { const result = shell.grep(); t.truthy(shell.error()); t.is(result.code, 2); + t.is(shell.errorCode(), 2); }); test('too few args', t => { From 90e8c8cc8e56fe118c33cd7e97c9d4cf62f4c12b Mon Sep 17 00:00:00 2001 From: Jessie France Date: Wed, 7 Jul 2021 10:54:12 -0600 Subject: [PATCH 3/3] test(errorCode): test for when code is 0 --- test/ls.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/ls.js b/test/ls.js index 0163f6f73..987ecf763 100644 --- a/test/ls.js +++ b/test/ls.js @@ -40,6 +40,7 @@ test('it\'s ok to use no arguments', t => { const result = shell.ls(); t.falsy(shell.error()); t.is(result.code, 0); + t.is(shell.errorCode(), 0); }); test('root directory', t => {