mirror of https://github.com/grpc/grpc-node.git
Merge pull request #175 from murgatroid99/file_error_improvement
Improve module load error message when the directory does not exist
This commit is contained in:
commit
650b5d5781
|
|
@ -31,17 +31,26 @@ var binding;
|
||||||
try {
|
try {
|
||||||
binding = require(binding_path);
|
binding = require(binding_path);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var fs = require('fs');
|
let fs = require('fs');
|
||||||
var searchPath = path.dirname(path.dirname(binding_path));
|
let searchPath = path.dirname(path.dirname(binding_path));
|
||||||
var searchName = path.basename(path.dirname(binding_path));
|
let searchName = path.basename(path.dirname(binding_path));
|
||||||
var foundNames = fs.readdirSync(searchPath);
|
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) {
|
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}
|
Expected directory: ${searchName}
|
||||||
Found: [${foundNames.join(', ')}]
|
Found: [${foundNames.join(', ')}]
|
||||||
This problem can often be fixed by running "npm rebuild" on the current system
|
This problem can often be fixed by running "npm rebuild" on the current system
|
||||||
Original error: ${e.message}`;
|
Original error: ${e.message}`;
|
||||||
var error = new Error(message);
|
let error = new Error(message);
|
||||||
error.code = e.code;
|
error.code = e.code;
|
||||||
throw error;
|
throw error;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue