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

Async API changes may break plugins #3566

Closed
raybellis opened this issue Feb 28, 2019 · 15 comments
Closed

Async API changes may break plugins #3566

raybellis opened this issue Feb 28, 2019 · 15 comments
Labels
async-migration Migration from callback-style programming to async functions plugin framework
Milestone

Comments

@raybellis
Copy link
Contributor

Most of the exported functions from the Etherpad internals will no longer take callback parameters in Etherpad 1.8+ (see #3540) and return Promises instead. This may break plugins that rely on those functions.

If backwards compatibility is required one solution may be to use the nodeify module to conditionally wrap the invocations of those exported functions.

@raybellis
Copy link
Contributor Author

raybellis commented Feb 28, 2019

Here's an example of how an existing plugin has been modified to provide backwards compatibility:

https://github.com/raybellis/ep_small_list

and also an example of how that same plugin would now be written if backwards compatibility is not required:

https://gist.github.com/raybellis/0a99d4762364605223bb79f84e4d59cf

NB: I would expect to be able to write a cleaner method to achieve the backward compatibility such that if multiple functions are to be wrapped it wouldn't take that amount of code for each function, perhaps even adding a module to the core distribution to handle the bulk of it for them.

@muxator muxator added this to the 1.8 milestone Feb 28, 2019
@muxator muxator added async-migration Migration from callback-style programming to async functions and removed stale code labels Feb 28, 2019
@raybellis
Copy link
Contributor Author

We should probably add some sort of Etherpad API versioning to the internal modules (collectively, not per module) so that the /admin page can indicate which plugins are compatible.

@Wikinaut
Copy link
Contributor

@raybellis Just as an idea: perhaps the compatibility can programmatically be tested at runtime, perhaps at least in some cases.

@raybellis
Copy link
Contributor Author

@Wikinaut see my forked version of your plugin, which does just that.

@Wikinaut
Copy link
Contributor

@raybellis In general I meant above: Etherpad core (admin module) can perhaps test (with assertions?) whether or not the installed plugins are async-compatible.

@raybellis
Copy link
Contributor Author

Oh, I see - the other way around? That's kind of what I meant by a versioning system, i.e. an expectation that each plugin's ep.json file specifies its minimum required Etherpad version. It would be very difficult to actually programmatically figure out whether a plugin is using callbacks or not.

@raybellis
Copy link
Contributor Author

I've made good progress writing some additional code that adds callback compatibility back into all of the exported functions that are now async, such that the ep_small_list plugin now works again without modification.

The code is slightly hacky, insomuch as it uses eval to create a new wrapper function that has the same arity as the existing functions. It's committed to my async branch (commit 64fdc73) so that it can be cherry picked if you want it.

Further testing is however stalled due to #3567.

@Wikinaut
Copy link
Contributor

Wikinaut commented Feb 28, 2019

@raybellis I confirm that also my installation (currently 64fdc73 ) is now working with the original ep_small_list plugin. Thank you very much.

@muxator
Copy link
Contributor

muxator commented Mar 2, 2019

Hi, I still did not integrate this into async-PR.

@muxator
Copy link
Contributor

muxator commented Mar 7, 2019

Hi, I am going to merge #3559 now. It contains all of your work on the async branch, except for your proposed fix for this issue (64fdc73), to give us more time to think about a solution.

If we'll continue to like that approach, please remember me to cherry pick this change in the next days.

@raybellis
Copy link
Contributor Author

The eval hack is only necessary to preserve the arity of the original functions, and was added to allow clients of the API elect to probe the arity to check whether the API is callback or promise -based (per my first attempt to show how to support either model).

Since the patch adds back in the ability to use either method based on the arguments received the support for arity testing could be dropped, and the wrappers generated as simple closures.

@muxator
Copy link
Contributor

muxator commented Dec 7, 2019

I have lost context about this issue, but I am going to release 1.8.0 anyway.
Moving to 1.8.1 to keep track of it.

@mspae
Copy link

mspae commented Dec 20, 2019

I've cloned two existing but apparently not maintained plugins and refactored them to work with the async functions:

Note that I provide no further assurances that these are in any way safe or usable.

BTW awesome that you refactored this @raybellis – the plugin code is much nicer to read now it uses async/await.

I think once this is released as a proper release there would need to be a big notice saying that there are severe breaking changes in the plugin API I think otherwise people might be confused. Also from a strict semver perspective: Would the proper release version not be 2.0.0 since there are breaking changes? – I don't know if this project follows this spec. There are certainly other options.

@JohnMcLear
Copy link
Member

JohnMcLear commented Mar 29, 2020

Hey guys, I already refactored most of my plugins so they should work. Is there a reason this issue is still open?

@muxator
Copy link
Contributor

muxator commented Apr 21, 2020

We can close this issue, now that the first point release (1.8.3) after the async rewrite (1.8.0) is ready to be released, and the few actively maintained plugins have been adapted.

Thanks.

@muxator muxator closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async-migration Migration from callback-style programming to async functions plugin framework
Projects
None yet
Development

No branches or pull requests

5 participants