From 7a8f54b53e70b81073955e020c115b0062c6ad69 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Wed, 19 Jan 2022 10:19:23 +0100 Subject: [PATCH] Fix extension function fallbacks As reported in #556, when the extension is not installed or fails to load, calls to certain extension functions will fail. The issue mentions the `runningInContainer` broken being broken on the main branch. PR #554 also removes some safety checks that cause the same issue for the `diagnoseRaw` function. Those safety checks were removed because they did not what expected, tracking if the extension was running or not. For both functions I've implemented a no-operations function. This will fix any errors on calls to these functions. Other functions that call these functions need to handle receiving no return value. Part of #556, but doesn't fix it entirely. We should call more function calls. These ones were the most obvious ones. Based on PR #554. --- .../.changesets/fix-extension-fallback-functions.md | 6 ++++++ .../nodejs/src/__tests__/extension.failure.test.ts | 12 ++++++++++++ packages/nodejs/src/extension.ts | 2 +- packages/nodejs/src/extension_wrapper.ts | 5 ++++- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 packages/nodejs/.changesets/fix-extension-fallback-functions.md diff --git a/packages/nodejs/.changesets/fix-extension-fallback-functions.md b/packages/nodejs/.changesets/fix-extension-fallback-functions.md new file mode 100644 index 000000000..b169ec653 --- /dev/null +++ b/packages/nodejs/.changesets/fix-extension-fallback-functions.md @@ -0,0 +1,6 @@ +--- +bump: "patch" +type: "fix" +--- + +Fix the extension function fallbacks on installation failure. When the extension fails to install and calls are made to the unloaded functions, it will no longer throw an error. diff --git a/packages/nodejs/src/__tests__/extension.failure.test.ts b/packages/nodejs/src/__tests__/extension.failure.test.ts index 73c6caccb..226dad43b 100644 --- a/packages/nodejs/src/__tests__/extension.failure.test.ts +++ b/packages/nodejs/src/__tests__/extension.failure.test.ts @@ -26,4 +26,16 @@ describe("Extension", () => { ext.stop() }).not.toThrow() }) + + it("does not error on diagnoseRaw", () => { + expect(() => { + ext.diagnoseRaw() + }).not.toThrow() + }) + + it("does not error on runningInContainer", () => { + expect(() => { + ext.diagnoseRaw() + }).not.toThrow() + }) }) diff --git a/packages/nodejs/src/extension.ts b/packages/nodejs/src/extension.ts index bf12b2612..7562e3cf2 100644 --- a/packages/nodejs/src/extension.ts +++ b/packages/nodejs/src/extension.ts @@ -48,7 +48,7 @@ export class Extension { } catch (error) { return { error: error, - output: diagnostics_report_string.split("\n") + output: (diagnostics_report_string || "").split("\n") } } } diff --git a/packages/nodejs/src/extension_wrapper.ts b/packages/nodejs/src/extension_wrapper.ts index c2510d974..cb63adb60 100644 --- a/packages/nodejs/src/extension_wrapper.ts +++ b/packages/nodejs/src/extension_wrapper.ts @@ -13,7 +13,10 @@ try { throw new Error("Extension module not loaded") }, stop() { - return + }, + diagnoseRaw() { + }, + runningInContainer() { } } } as ExtensionWrapper