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

Improve module load error message when the directory does not exist #175

Merged
merged 2 commits into from
Feb 8, 2018
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: 16 additions & 6 deletions packages/grpc-native-core/src/grpc_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ 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);
let fs = require('fs');
let searchPath = path.dirname(path.dirname(binding_path));
let searchName = path.basename(path.dirname(binding_path));
let foundNames;
try {
foundNames = fs.readdirSync(searchPath);
} catch (readDirError) {
let message = `The gRPC binary module was not installed
This may be fixed by running "npm rebuild"
Original error: ${e.message}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be readDirError.message? (And same with e.code below)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it seems like the first two lines can fit together on a single line.

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, it's supposed to be e.message and e.code, because e is the original error that we are trying to communicate.

Also, I just made the structure of the error message match the other error. I could merge those lines, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I merged the lines.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, didn't see that 🙃

let error = new Error(message);
error.code = e.code;
throw error;
}
if (foundNames.indexOf(searchName) === -1) {
var message = `Failed to load gRPC binary module because it was not installed for the current system
let 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);
let error = new Error(message);
error.code = e.code;
throw error;
} else {
Expand Down