Skip to content

Commit

Permalink
Merge pull request #175 from murgatroid99/file_error_improvement
Browse files Browse the repository at this point in the history
Improve module load error message when the directory does not exist
  • Loading branch information
murgatroid99 authored Feb 8, 2018
2 parents 77e4376 + b7f122b commit 650b5d5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 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,26 @@ 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}`;
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

0 comments on commit 650b5d5

Please sign in to comment.