-
-
Notifications
You must be signed in to change notification settings - Fork 337
fix(plugins): surface the real reason a plugin bundle fails to load (#1915) #1927
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // | ||
| // PluginBundleLoader.swift | ||
| // TablePro | ||
| // | ||
|
|
||
| import Foundation | ||
| import os | ||
|
|
||
| enum PluginBundleLoader { | ||
| private static let logger = Logger(subsystem: "com.TablePro", category: "PluginBundleLoader") | ||
|
|
||
| static func load(_ bundle: Bundle) throws { | ||
| do { | ||
| try bundle.loadAndReturnError() | ||
| } catch { | ||
| let nsError = error as NSError | ||
| let reason = describeLoadFailure(nsError) | ||
| let detail = nsError.userInfo[NSDebugDescriptionErrorKey] as? String ?? nsError.localizedDescription | ||
| logger.error( | ||
| "Bundle load failed for \(bundle.bundleURL.lastPathComponent, privacy: .public) [\(nsError.domain, privacy: .public) \(nsError.code, privacy: .public)]: \(reason, privacy: .public) [\(detail, privacy: .public)]" | ||
| ) | ||
| throw PluginError.invalidBundle(reason) | ||
| } | ||
| } | ||
|
|
||
| static func describeLoadFailure(_ error: NSError) -> String { | ||
| switch error.code { | ||
| case NSFileNoSuchFileError: | ||
| return String(localized: "The plugin's executable file is missing.") | ||
| case NSExecutableNotLoadableError: | ||
| return String(localized: "The plugin's executable couldn't be loaded. It may be damaged or improperly signed.") | ||
| case NSExecutableArchitectureMismatchError: | ||
| return String(localized: "The plugin doesn't include a build for this Mac's processor architecture.") | ||
| case NSExecutableRuntimeMismatchError: | ||
| return String(localized: "The plugin was built for an incompatible runtime.") | ||
| case NSExecutableLoadError: | ||
| return String(localized: "The plugin depends on a component that's missing or incompatible with this Mac.") | ||
| case NSExecutableLinkError: | ||
| return String(localized: "The plugin isn't compatible with this version of TablePro. Update the app or reinstall the plugin.") | ||
| default: | ||
| return error.localizedFailureReason ?? error.localizedDescription | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // | ||
| // PluginBundleLoaderTests.swift | ||
| // TableProTests | ||
| // | ||
|
|
||
| import Foundation | ||
| @testable import TablePro | ||
| import Testing | ||
|
|
||
| @Suite("PluginBundleLoader.describeLoadFailure") | ||
| struct PluginBundleLoaderDescribeLoadFailureTests { | ||
| private func makeError(_ code: Int, debug: String? = nil, failureReason: String? = nil) -> NSError { | ||
| var userInfo: [String: Any] = [:] | ||
| if let debug { userInfo[NSDebugDescriptionErrorKey] = debug } | ||
| if let failureReason { userInfo[NSLocalizedFailureReasonErrorKey] = failureReason } | ||
| return NSError(domain: NSCocoaErrorDomain, code: code, userInfo: userInfo) | ||
| } | ||
|
|
||
| @Test("missing executable file reports a missing-file reason") | ||
| func missingFile() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSFileNoSuchFileError)) | ||
| #expect(reason.localizedCaseInsensitiveContains("missing")) | ||
| #expect(!reason.contains("Bundle failed to load executable")) | ||
| } | ||
|
|
||
| @Test("not-loadable executable reports a damaged executable") | ||
| func notLoadable() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSExecutableNotLoadableError)) | ||
| #expect(reason.localizedCaseInsensitiveContains("loaded") || reason.localizedCaseInsensitiveContains("damaged")) | ||
| } | ||
|
|
||
| @Test("architecture mismatch names the processor architecture") | ||
| func architectureMismatch() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSExecutableArchitectureMismatchError)) | ||
| #expect(reason.localizedCaseInsensitiveContains("architecture")) | ||
| } | ||
|
|
||
| @Test("runtime mismatch reports an incompatible runtime") | ||
| func runtimeMismatch() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSExecutableRuntimeMismatchError)) | ||
| #expect(reason.localizedCaseInsensitiveContains("runtime")) | ||
| } | ||
|
|
||
| @Test("missing dependency reports a missing component") | ||
| func missingDependency() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSExecutableLoadError)) | ||
| #expect(reason.localizedCaseInsensitiveContains("component")) | ||
| } | ||
|
|
||
| @Test("link error points at app or plugin incompatibility") | ||
| func linkError() { | ||
| let reason = PluginBundleLoader.describeLoadFailure(makeError(NSExecutableLinkError)) | ||
| #expect(reason.contains("TablePro")) | ||
| } | ||
|
|
||
| @Test("unknown code falls back to the OS-provided reason") | ||
| func unknownCodeFallsBack() { | ||
| let reason = PluginBundleLoader.describeLoadFailure( | ||
| makeError(999_999, failureReason: "Custom underlying reason") | ||
| ) | ||
| #expect(reason == "Custom underlying reason") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a lazy bundle fails after initial startup, this only appends to
rejectedPlugins; noAppEvents.shared.pluginsRejectedevent is sent.PluginNotificationServicesubscribes exclusively to that event (set up inAppDelegate), while the only sender is the initial reconciliation path that has already run, so the newly added rejected-plugin notification is never delivered for this on-demand failure despite the intended reporting behavior.Useful? React with 👍 / 👎.