Skip to content

Commit f52a824

Browse files
authored
Fix extension function fallbacks (#557)
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.
1 parent 56fb794 commit f52a824

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
bump: "patch"
3+
type: "fix"
4+
---
5+
6+
Fix the extension function fallbacks on installation failure. When the extension fails to install and calls are made to the not loaded functions, it will no longer throw an error.

packages/nodejs/src/__tests__/extension.failure.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,15 @@ describe("Extension", () => {
3030
ext.stop()
3131
}).not.toThrow()
3232
})
33+
34+
it("does not error on diagnoseRaw", () => {
35+
expect(ext.diagnose()).toMatchObject({
36+
error: expect.any(Error),
37+
output: [""]
38+
})
39+
})
40+
41+
it("does not error on runningInContainer", () => {
42+
expect(ext.runningInContainer()).toBeUndefined()
43+
})
3344
})

packages/nodejs/src/extension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class Extension {
4848
} catch (error) {
4949
return {
5050
error: error,
51-
output: diagnostics_report_string.split("\n")
51+
output: (diagnostics_report_string || "").split("\n")
5252
}
5353
}
5454
}

packages/nodejs/src/extension_wrapper.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ try {
1212
start() {
1313
throw new Error("Extension module not loaded")
1414
},
15-
stop() {
16-
return
17-
}
15+
stop() {},
16+
diagnoseRaw() {},
17+
runningInContainer() {}
1818
}
1919
} as ExtensionWrapper
2020
}

0 commit comments

Comments
 (0)