pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

`Workspace::onDidAddTextEditor` handlers can interfere with each other

Open savetheclocktower opened this issue 4 months ago • 1 comments

Thanks in advance for your bug report!

  • [x] Have you reproduced issue in safe mode?
  • [x] Have you used the debugging guide to try to resolve the issue?
  • [x] Have you checked our FAQs to make sure your question isn't answered there?
  • [x] Have you checked to make sure your issue does not already exist?
  • [x] Have you checked you are on the latest release of Pulsar?

What happened?

Suppose I do this:

atom.workspace.onDidAddTextEditor(({ textEditor }) => {
  textEditor.methodThatDoesNotExist();
});

There's a good chance I have now screwed up all the other packages that need to respond to new editors in the workspace. We don't seem to be catching exceptions that are thrown in these handlers, so they do not run in isolation from one another.

In this example alone, here are the things that should happen but don't:

  • The tabs package does not focus the newly-opened editor; you must switch tabs manually.
  • The linter package does not annotate the editor with squiggles to correspond to any linting errors.
  • The atom-prettier package does not reformat the code on save (if you've configured it to do so) because it missed its opportunity to attach an onWillSave handler to the buffer.

I am writing this down before I forget because I'm neck-deep on another task, but this troubles me because it might be baked into event-kit altogether. Hoping I'm just missing something simple here because it seems like a glaring flaw.

Pulsar version

Reproduced on PulsarNext, but should be reproducible on any version

Which OS does this happen on?

❓ Other(Please specify in the OS details field below)

OS details

Irrelevant

Which CPU architecture are you running this on?

Apple M-series

What steps are needed to reproduce this?

atom.workspace.onDidAddTextEditor(({ textEditor }) => {
  textEditor.methodThatDoesNotExist();
});
  1. Run the above code in the developer tools console (or place it in your init.js and reload the window)
  2. Open any new editor tab (choose something in the tree view or open it via the fuzzy finder)
  3. Observe how the new editor is not focused, even though a tab is created for it in the tab bar

Additional Information:

No response

savetheclocktower avatar Aug 24 '25 17:08 savetheclocktower

Ah, I see.

By default, event-kit is designed to stop subsequent event handlers when any of an event's handlers throws an exception. But this behavior can be changed by registering an exception handler on the Emitter itself.

So the emitter for Workspace needs to define such a handler in order to guarantee that one buggy package doesn't ruin the experience for the user.

savetheclocktower avatar Aug 24 '25 18:08 savetheclocktower