Add error handling to extension load #13204
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13205
Technical notes summary
This PR improves the error handling when we load extensions.
I checked out the elemental-ui extension with the 2.9 branch, built it and served it up locally and developer loaded it into a 2.11 UI running locally - to reproduce trying to load a Vue 2 extension into Vue 3.
We don't have any exception handling in the load - the script for the extension loads, so our onloadhandler gets called. The script has an exception when it is evaluated at load time (error reading 'extend'), but this does not affect our code path - we check window[id]` is set, but because the injected script errored, it is an empty object and does not have the default function, so the real error for us is when we call that method here - https://github.com/rancher/dashboard/blob/master/shell/core/plugins.js#L116 - this throws an unhandled exception.
In the PR, I have added a check for the default function and added a try/catch around the call of it.
With this, the UI handles the load error. Note when running in dev, you will get the red overlay saying there is an unhandled exception (this is due to the error with the script load), but if you close it, our UI is working fine - before, you'd be stuck with the loading spinner. In production you wont' get the red overlay.
Areas or cases that should be tested
Extension loading
Checklist