Skip to content

Commit

Permalink
Fix extension function fallbacks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tombruijn committed Jan 19, 2022
1 parent 24ac4f9 commit 7a8f54b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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.
12 changes: 12 additions & 0 deletions packages/nodejs/src/__tests__/extension.failure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
2 changes: 1 addition & 1 deletion packages/nodejs/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Extension {
} catch (error) {
return {
error: error,
output: diagnostics_report_string.split("\n")
output: (diagnostics_report_string || "").split("\n")
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/nodejs/src/extension_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ try {
throw new Error("Extension module not loaded")
},
stop() {
return
},
diagnoseRaw() {
},
runningInContainer() {
}
}
} as ExtensionWrapper
Expand Down

0 comments on commit 7a8f54b

Please sign in to comment.