Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report errors when analyzing extensions #4380

Merged
merged 4 commits into from Nov 14, 2023
Merged

fix: report errors when analyzing extensions #4380

merged 4 commits into from Nov 14, 2023

Conversation

deboer-tim
Copy link
Collaborator

What does this PR do?

Since PR #2990 is very old I'm creating a new one.

Adds an error property to analyzed extensions, and analyzeExtension() sets it whenever there is a problem loading a folder instead of returning undefined. Added error for missing manifest entries.

Updated callers to check for error instead of undefined, and send an error when trying to install an extension that has an error.

Tests updated to confirm an error is being created.

Screenshot/screencast of this PR

Screenshot 2023-10-17 at 1 26 31 PM

What issues does this PR fix or reference?

Fixes #2871.

How to test this PR?

See issue #2871 - try installing this extension: quay.io/lstocchi/sample-podman-extension:v1

@deboer-tim deboer-tim requested review from benoitf and a team as code owners October 17, 2023 17:50
@deboer-tim deboer-tim requested review from dgolovin and lstocchi and removed request for a team October 17, 2023 17:50
Copy link
Collaborator

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM

probably add tests to check specific error message returned

return undefined;
error = `Ignoring extension ${extensionPath} without package.json file`;
console.warn(error);
return { error } as AnalyzedExtension;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I think it may lead to client's error as the object they'll get is not compliant to the typescript contract.
So while I see no problem of using that pattern in tests, we should not in main code as it may lead to runtime errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, and I agree that would be better. I've changed it to return a regular AnalyzedExtension now. I didn't want to change the API contract, so added a couple 'fake' values like id and name (felt like these could cause problems if empty), and tried to give reasonable defaults/undefined elsewhere. I wasn't sure if there's a simpler way to do the subscription/dispose(), please review again.

packages/main/src/plugin/extension-loader.ts Outdated Show resolved Hide resolved
Adds an error property to analyzed extensions, and analyzeExtension() sets
it whenever there is a problem loading a folder instead of returning
undefined. Updated callers to check for error instead of undefined, and
send an error when trying to install an extension that has an error.
Tests updated to confirm an error is being created.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
Return an AnalyzedExtension even when the manifest can't be found,
with some default values.

Include the required manifest properties in error message.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
Copy link
Collaborator

@benoitf benoitf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, LGTM

I'll need to test with an extension

Simplify subscriptions/dispose for error case.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
@deboer-tim
Copy link
Collaborator Author

@benoitf could you take another look?

Copy link
Contributor

@lstocchi lstocchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

packages/main/src/plugin/extension-loader.ts Outdated Show resolved Hide resolved
packages/main/src/plugin/extension-loader.ts Outdated Show resolved Hide resolved
packages/main/src/plugin/extension-loader.ts Outdated Show resolved Hide resolved
The `as AnalyzedExtension` isn't needed anymore, since analyzeExtension()
can no longer return undefined.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
@deboer-tim
Copy link
Collaborator Author

@dgolovin good to remove your request (fixed) and merge?

@deboer-tim deboer-tim merged commit 4951487 into main Nov 14, 2023
9 checks passed
@deboer-tim deboer-tim deleted the extension2 branch November 14, 2023 20:42
@podman-desktop-bot podman-desktop-bot added this to the 1.6.0 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When installing an extension that has an undefined displayName the extensions section gets broken
5 participants