From 51c8503c0107a3b17eef749abaa677e8ad8e0450 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 8 Feb 2018 10:21:18 -0800 Subject: [PATCH 1/2] Improve module load error message when the directory does not exist --- .../grpc-native-core/src/grpc_extension.js | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/grpc-native-core/src/grpc_extension.js b/packages/grpc-native-core/src/grpc_extension.js index 46e2721d1..0ef399d17 100644 --- a/packages/grpc-native-core/src/grpc_extension.js +++ b/packages/grpc-native-core/src/grpc_extension.js @@ -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}`; + 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 { From b7f122bb6cc236196ed6968e63f1185eabf43858 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Thu, 8 Feb 2018 11:35:20 -0800 Subject: [PATCH 2/2] Merge two lines of the error message --- packages/grpc-native-core/src/grpc_extension.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/grpc-native-core/src/grpc_extension.js b/packages/grpc-native-core/src/grpc_extension.js index 0ef399d17..9a023b7c3 100644 --- a/packages/grpc-native-core/src/grpc_extension.js +++ b/packages/grpc-native-core/src/grpc_extension.js @@ -38,8 +38,7 @@ try { try { foundNames = fs.readdirSync(searchPath); } catch (readDirError) { - let message = `The gRPC binary module was not installed -This may be fixed by running "npm rebuild" + 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;