Skip to content

Commit

Permalink
Merge pull request #106 from murgatroid99/helpful_load_error_messages
Browse files Browse the repository at this point in the history
Add more helpful error message for failure to load extension
  • Loading branch information
murgatroid99 authored Nov 30, 2017
2 parents 82b03c3 + 02e70cb commit 89c60cb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/grpc-native-core/src/grpc_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 directory: ${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;

0 comments on commit 89c60cb

Please sign in to comment.