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

Don't throw when re-registering a plugin #4140

Merged
merged 2 commits into from
Mar 2, 2017
Merged

Don't throw when re-registering a plugin #4140

merged 2 commits into from
Mar 2, 2017

Conversation

misteroneill
Copy link
Member

Currently, if a plugin is re-registered, it will throw an error. On the face, this makes sense, but it comes with two issues:

  1. It will totally break in an unrecoverable way in a case where it might not actually be a break.
  2. Nothing else has this behavior - components and techs do not throw.

Requirements Checklist

  • Feature implemented / Bug fixed
  • Reviewed by Two Core Contributors

@misteroneill misteroneill added this to To Do in 6.0 Feb 28, 2017
@misteroneill misteroneill moved this from To Do to Ready for Review in 6.0 Feb 28, 2017
throw new Error(`Illegal plugin name, "${name}", already exists.`);
if (pluginExists(name)) {
log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`);
} else if (Player.prototype.hasOwnProperty(name)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an else if because if a plugin exists, it will have a method on the Player.prototype, but if the plugin does not exist and the name matches a Player.prototype method, it's an actual player method.

Copy link
Member

Choose a reason for hiding this comment

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

This sounds like a reasonable compromise.

throw new Error(`Illegal plugin name, "${name}", already exists.`);
if (pluginExists(name)) {
log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`);
} else if (Player.prototype.hasOwnProperty(name)) {
Copy link
Member

Choose a reason for hiding this comment

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

This sounds like a reasonable compromise.

@gkatsev
Copy link
Member

gkatsev commented Feb 28, 2017

This should be rebased against master, will make tests run better.

@gkatsev gkatsev merged commit 326398d into master Mar 2, 2017
@gkatsev gkatsev deleted the plugin-no-throw branch March 2, 2017 16:17
if (pluginExists(name) || Player.prototype.hasOwnProperty(name)) {
throw new Error(`Illegal plugin name, "${name}", already exists.`);
if (pluginExists(name)) {
log.warn(`A plugin named "${name}" already exists. You may want to avoid re-registering plugins!`);
Copy link
Member

Choose a reason for hiding this comment

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

@misteroneill when you get the chance, can you make another PR that silences this warning in the plugin tests?

@gkatsev gkatsev moved this from Ready for Review to Done in 6.0 Mar 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
6.0
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants