From 5e420f95b19d1c860f0288a91bc7888b1eac577a Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 19 Aug 2018 00:57:41 -0400 Subject: [PATCH 1/2] os: destructure ERR_SYSTEM_ERROR properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/22394 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Tobias Nießen --- lib/os.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/os.js b/lib/os.js index e65c11fc58ca7f..15d06f1576f2e5 100644 --- a/lib/os.js +++ b/lib/os.js @@ -26,7 +26,7 @@ const constants = process.binding('constants').os; const { deprecate } = require('internal/util'); const isWindows = process.platform === 'win32'; -const { ERR_SYSTEM_ERROR } = require('internal/errors'); +const { codes: { ERR_SYSTEM_ERROR } } = require('internal/errors'); const { getCPUs, From 8d05a1590aaeab07050e019ac892e1ebacac456d Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 20 Aug 2018 09:10:06 -0400 Subject: [PATCH 2/2] test: cover error case in os getCheckedFunction() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getCheckedFunction() is used internally by the os module to handle errors from the binding layer in several methods. This commit adds a test for the case where the binding layer returns an error. PR-URL: https://github.com/nodejs/node/pull/22394 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Tobias Nießen --- test/parallel/test-os-checked-function.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/parallel/test-os-checked-function.js diff --git a/test/parallel/test-os-checked-function.js b/test/parallel/test-os-checked-function.js new file mode 100644 index 00000000000000..04c2c3a1f82ea3 --- /dev/null +++ b/test/parallel/test-os-checked-function.js @@ -0,0 +1,15 @@ +'use strict'; +// Monkey patch the os binding before requiring any other modules, including +// common, which requires the os module. +process.binding('os').getHomeDirectory = function(ctx) { + ctx.syscall = 'foo'; + ctx.code = 'bar'; + ctx.message = 'baz'; +}; + +const common = require('../common'); +const os = require('os'); + +common.expectsError(os.homedir, { + message: /^A system error occurred: foo returned bar \(baz\)$/ +});