fix: return clear error for duplicate plugin names (fix #13798)#14919
fix: return clear error for duplicate plugin names (fix #13798)#14919akuligowski9 wants to merge 3 commits intotauri-apps:devfrom
Conversation
FabianLars
left a comment
There was a problem hiding this comment.
Thanks for the PR! Would you mind signing (and force-pushing) your commit? Our branch protection rules require that :)
| if self.has(plugin.name()) { | ||
| return Err(crate::Error::PluginNameAlreadyExists(plugin.name().to_string())); | ||
| } |
There was a problem hiding this comment.
I don't think it makes sense to have the very same check both here and in the 2 register() methods above
There was a problem hiding this comment.
Good point — I've moved the duplicate check to Builder::plugin() only, so it catches mistakes early at app setup. Runtime registration via AppHandle::plugin() keeps the existing replace behavior, so devs still have the choice to handle duplicates themselves.
| let name = plugin.name().to_string(); | ||
| if self.plugins.has(&name) { | ||
| log::warn!("plugin `{name}` already registered, replacing with new instance"); | ||
| self.plugins.unregister(&name); |
There was a problem hiding this comment.
not the biggest fan of the behavior change. i think devs should handle that themselves so they have a choice
There was a problem hiding this comment.
Agreed — I've updated the approach. The duplicate check now only applies at build time in Builder::plugin(), where it's clearly a developer mistake (registering the same plugin twice in setup code). Runtime registration via AppHandle::plugin() keeps the existing silent-replace behavior, so devs retain full control.
34d8a9f to
82b277a
Compare
Package Changes Through 82b277aThere are 4 changes which include tauri-cli with patch, @tauri-apps/cli with patch, tauri-bundler with patch, tauri with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
8867a39 to
2e53f1e
Compare
…3798) Move the duplicate plugin check to Builder::plugin() only, so it catches mistakes early at app setup. Runtime registration via AppHandle::plugin() keeps the existing replace behavior, giving devs the choice to handle duplicates themselves. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2e53f1e to
c3466e4
Compare
|
Hi! Just a gentle ping — this PR adds a clear error message for duplicate plugin names (resolves #13798) and has been ready for review since February. Let me know if there's anything I should adjust! |
Summary
PluginNameAlreadyExists(String)error variant (consistent withWindowLabelAlreadyExists/WebviewLabelAlreadyExists)PluginStore::register()now returnsResult<()>and rejects duplicatesAppHandle::plugin()checks for duplicates before runninginitialize(), then propagates the errorBuilder::plugin()warns vialog::warn!and replaces the old plugin (preserves backward compat since it returnsSelf)Motivation
When a user registers two plugins with the same name, the duplicate silently replaces the original. If the replaced plugin was a core plugin (e.g.
"path","event","window"), the app later panics with an inscrutablestate() called before manage()— giving zero indication that a duplicate plugin name was the root cause.How it works
Builderlog::warn!, second replaces first (backward compat)register_core_plugins()→Err(PluginNameAlreadyExists("window"))— clear errorAppHandle::plugin()Err(PluginNameAlreadyExists("my-plugin"))— caller can handle itTest plan
cargo check -p tauricompilescargo clippy -p tauri -- -D warningspassescargo test -p tauri— all 52 unit tests + 86 doc-tests pass🤖 Generated with Claude Code