Skip to content

Commit 0aa938a

Browse files
author
Nadezhda Atanasova
authored
Return information about the error if loadExtension fails (#2899)
* Add actual error when loading extension * PR comments
1 parent 2adfc16 commit 0aa938a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/services/extensibility-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class ExtensibilityService implements IExtensibilityService {
8484
return { extensionName };
8585
} catch (error) {
8686
this.$logger.warn(`Error while loading ${extensionName} is: ${error.message}`);
87-
const err = <IExtensionLoadingError>new Error(`Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds.`);
87+
const err = <IExtensionLoadingError>new Error(`Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds. Error: ${error.message}`);
8888
err.extensionName = extensionName;
8989
throw err;
9090
}

test/services/extensibility-service.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ describe("extensibilityService", () => {
238238
};
239239

240240
const expectedResults: any[] = _.map(extensionNames, extensionName => ({ extensionName }));
241-
expectedResults[0] = new Error("Unable to load extension extension1. You will not be able to use the functionality that it adds.");
241+
expectedResults[0] = new Error("Unable to load extension extension1. You will not be able to use the functionality that it adds. Error: Unable to load module.");
242242
const extensibilityService: IExtensibilityService = testInjector.resolve(ExtensibilityService);
243243
const promises = extensibilityService.loadExtensions();
244244
assert.deepEqual(promises.length, extensionNames.length);
@@ -258,6 +258,7 @@ describe("extensibilityService", () => {
258258
const testInjector = getTestInjector();
259259
const extensionNames = ["extension1", "extension2", "extension3"];
260260
const fs: IFileSystem = testInjector.resolve("fs");
261+
const expectedErrorMessage = `Unable to read ${constants.NODE_MODULES_FOLDER_NAME} dir.`;
261262
fs.exists = (pathToCheck: string): boolean => path.basename(pathToCheck) === "extensions" || path.basename(pathToCheck) === constants.PACKAGE_JSON_FILE_NAME;
262263
fs.readJson = (filename: string, encoding?: string): any => {
263264
const dependencies: any = {};
@@ -272,7 +273,7 @@ describe("extensibilityService", () => {
272273
fs.readDirectory = (dir: string): string[] => {
273274
isReadDirCalled = true;
274275
assert.deepEqual(path.basename(dir), constants.NODE_MODULES_FOLDER_NAME);
275-
throw new Error(`Unable to read ${constants.NODE_MODULES_FOLDER_NAME} dir.`);
276+
throw new Error(expectedErrorMessage);
276277
};
277278

278279
const extensibilityService: IExtensibilityService = testInjector.resolve(ExtensibilityService);
@@ -283,7 +284,7 @@ describe("extensibilityService", () => {
283284
await loadExtensionPromise.then(res => { throw new Error("Shouldn't get here!"); },
284285
err => {
285286
const extensionName = extensionNames[index];
286-
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds.`);
287+
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds. Error: ${expectedErrorMessage}`);
287288
assert.deepEqual(err.extensionName, extensionName);
288289
});
289290
};
@@ -295,6 +296,9 @@ describe("extensibilityService", () => {
295296
it("rejects all promises when unable to install extensions to extension dir (simulate EPERM error)", async () => {
296297
const testInjector = getTestInjector();
297298
const extensionNames = ["extension1", "extension2", "extension3"];
299+
const expectedErrorMessages = ["Unable to install to node_modules dir.",
300+
"expected 'extension2' to deeply equal 'extension1'",
301+
"expected 'extension3' to deeply equal 'extension1'"];
298302
const fs: IFileSystem = testInjector.resolve("fs");
299303
fs.exists = (pathToCheck: string): boolean => path.basename(pathToCheck) === "extensions" || path.basename(pathToCheck) === constants.PACKAGE_JSON_FILE_NAME;
300304
fs.readJson = (filename: string, encoding?: string): any => {
@@ -315,10 +319,11 @@ describe("extensibilityService", () => {
315319

316320
let isNpmInstallCalled = false;
317321
const npm: INodePackageManager = testInjector.resolve("npm");
322+
const expectedErrorMessage = `Unable to install to ${constants.NODE_MODULES_FOLDER_NAME} dir.`;
318323
npm.install = async (packageName: string, pathToSave: string, config?: any): Promise<any> => {
319324
assert.deepEqual(packageName, extensionNames[0]);
320325
isNpmInstallCalled = true;
321-
throw new Error(`Unable to install to ${constants.NODE_MODULES_FOLDER_NAME} dir.`);
326+
throw new Error(expectedErrorMessage);
322327
};
323328

324329
const extensibilityService: IExtensibilityService = testInjector.resolve(ExtensibilityService);
@@ -327,11 +332,12 @@ describe("extensibilityService", () => {
327332
for (let index = 0; index < promises.length; index++) {
328333
const loadExtensionPromise = promises[index];
329334
await loadExtensionPromise.then(res => {
330-
console.log("######### res = ", res); throw new Error("Shouldn't get here!");
335+
throw new Error("Shouldn't get here!");
331336
},
337+
332338
err => {
333339
const extensionName = extensionNames[index];
334-
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds.`);
340+
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds. Error: ${expectedErrorMessages[index]}`);
335341
assert.deepEqual(err.extensionName, extensionName);
336342
});
337343
};
@@ -604,7 +610,7 @@ describe("extensibilityService", () => {
604610
await extensibilityService.loadExtension(extensionName);
605611
} catch (err) {
606612
isErrorRaised = true;
607-
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds.`);
613+
assert.deepEqual(err.message, `Unable to load extension ${extensionName}. You will not be able to use the functionality that it adds. Error: ${expectedErrorMessage}`);
608614
assert.deepEqual(err.extensionName, extensionName);
609615
}
610616

0 commit comments

Comments
 (0)