From df91f1c4fa740d38c9dccbc256a855f24f03a859 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 | 11 +++++++++++ packages/nodejs/src/extension.ts | 2 +- packages/nodejs/src/extension_wrapper.ts | 6 +++--- 4 files changed, 21 insertions(+), 4 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 b4738e630..57f2f221d 100644 --- a/packages/nodejs/src/__tests__/extension.failure.test.ts +++ b/packages/nodejs/src/__tests__/extension.failure.test.ts @@ -30,4 +30,15 @@ describe("Extension", () => { ext.stop() }).not.toThrow() }) + + it("does not error on diagnoseRaw", () => { + expect(ext.diagnose()).toMatchObject({ + error: expect.any(String), + output: [""] + }) + }) + + it("does not error on runningInContainer", () => { + expect(ext.runningInContainer()).toBeUndefined() + }) }) 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..44d16e5d5 100644 --- a/packages/nodejs/src/extension_wrapper.ts +++ b/packages/nodejs/src/extension_wrapper.ts @@ -12,9 +12,9 @@ try { start() { throw new Error("Extension module not loaded") }, - stop() { - return - } + stop() {}, + diagnoseRaw() {}, + runningInContainer() {} } } as ExtensionWrapper }