Catching when an essential view plugin has been removed

When an editor contains an extension which is considered essential for the functioning of the editor (such as the ViewPlugin in the collaborative editing example, without which changes in the editor wouldn’t be synced), it’s critical that a crash in the plugin doesn’t lead to it being silently removed from the view, which is what currently happens - apart from an error logged to the console.

I’m wondering which approach would be best, of the possible ways to avoid or detect this:

  1. Wrap everything in the plugin in try/catch, so that all errors can be handled appropriately (e.g. by setting an error state) without the plugin being removed. This seems reasonable, but what if the catch handler throws an error - it doesn’t guarantee that the plugin won’t be removed.
  2. Put something in the plugin’s destroy function, which is called when the plugin is removed. This seems like the right place to handle this, but it doesn’t seem to be possible to distinguish between the case where the plugin is being removed because it crashed and the case where the plugin is being removed during the normal editor closing process.
  3. Add another update listener, which runs after the essential view plugin, that has the sole responsibility of calling view.plugin(essentialPlugin) and handling the situation where that returns null (meaning that the essential plugin has been removed).

That sounds about right. Option 3 could also use the exceptionSink feature to only run its check when an actual exception has been caught.

1 Like

Unless I’m missing a way to set precedence, it seems that a function in the EditorView.exceptionSink facet is called before the view plugin which threw the error is removed, so it’s not possible to use the exception sink to check for the existence of a view plugin (at least not without using a timeout).