Skip to content

Commit 89c60cb

Browse files
authored
Merge pull request #106 from murgatroid99/helpful_load_error_messages
Add more helpful error message for failure to load extension
2 parents 82b03c3 + 02e70cb commit 89c60cb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/grpc-native-core/src/grpc_extension.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ var binary = require('node-pre-gyp/lib/pre-binding');
2727
var path = require('path');
2828
var binding_path =
2929
binary.find(path.resolve(path.join(__dirname, '../package.json')));
30-
var binding = require(binding_path);
30+
var binding;
31+
try {
32+
binding = require(binding_path);
33+
} catch (e) {
34+
var fs = require('fs');
35+
var searchPath = path.dirname(path.dirname(binding_path));
36+
var searchName = path.basename(path.dirname(binding_path));
37+
var foundNames = fs.readdirSync(searchPath);
38+
if (foundNames.indexOf(searchName) === -1) {
39+
var message = `Failed to load gRPC binary module because it was not installed for the current system
40+
Expected directory: ${searchName}
41+
Found: [${foundNames.join(', ')}]
42+
This problem can often be fixed by running "npm rebuild" on the current system
43+
Original error: ${e.message}`;
44+
var error = new Error(message);
45+
error.code = e.code;
46+
throw error;
47+
} else {
48+
throw e;
49+
}
50+
}
3151

3252
module.exports = binding;

0 commit comments

Comments
 (0)