From 7652ef74ed658d202b21ea8819c31cae34ed2cbc Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 29 Nov 2017 16:10:56 -0800 Subject: [PATCH 1/2] Add more helpful error message for failure to load extension --- .../grpc-native-core/src/grpc_extension.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/grpc-native-core/src/grpc_extension.js b/packages/grpc-native-core/src/grpc_extension.js index 77476f012..487280ef8 100644 --- a/packages/grpc-native-core/src/grpc_extension.js +++ b/packages/grpc-native-core/src/grpc_extension.js @@ -27,6 +27,26 @@ var binary = require('node-pre-gyp/lib/pre-binding'); var path = require('path'); var binding_path = binary.find(path.resolve(path.join(__dirname, '../package.json'))); -var binding = require(binding_path); +var binding; +try { + binding = require(binding_path); +} catch (e) { + var fs = require('fs'); + var searchPath = path.dirname(path.dirname(binding_path)); + var searchName = path.basename(path.dirname(binding_path)); + var foundNames = fs.readdirSync(searchPath); + if (foundNames.indexOf(searchName) === -1) { + var message = `Failed to load gRPC binary module because it was not installed for the current system +Expected: ${searchName} +Found: [${foundNames.join(', ')}] +This problem can often be fixed by running "npm rebuild" on the current system +Original error: ${e.message}`; + var error = new Error(message); + error.code = e.code; + throw error; + } else { + throw e; + } +} module.exports = binding; From 02e70cba374734e991648fcd01a7b92bfde20cec Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 29 Nov 2017 16:57:13 -0800 Subject: [PATCH 2/2] Improve message wording --- packages/grpc-native-core/src/grpc_extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/grpc-native-core/src/grpc_extension.js b/packages/grpc-native-core/src/grpc_extension.js index 487280ef8..46e2721d1 100644 --- a/packages/grpc-native-core/src/grpc_extension.js +++ b/packages/grpc-native-core/src/grpc_extension.js @@ -37,7 +37,7 @@ try { var foundNames = fs.readdirSync(searchPath); if (foundNames.indexOf(searchName) === -1) { var message = `Failed to load gRPC binary module because it was not installed for the current system -Expected: ${searchName} +Expected directory: ${searchName} Found: [${foundNames.join(', ')}] This problem can often be fixed by running "npm rebuild" on the current system Original error: ${e.message}`;