Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more helpful error message for failure to load extension #106

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ${searchName}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you mean binding_path here instead of searchName ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. searchName is the name of the directory that contains grpc_node.node. And that directory name contains the relevant information for diagnosing this problem. Plus, it can be directly (visually) compared with the contents of foundNames.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then maybe rephrase it a tiny bit, because the words "gRPC binary module" to me means grpc_node.node. Maybe you need to add the word "location" next to "Expected" ?

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;