pulsar-edit / pulsar

A Community-led Hyper-Hackable Text Editor
https://pulsar-edit.dev
Other
3.22k stars 137 forks source link

Assertion failed when writing markdown #898

Open jqueraltmo opened 7 months ago

jqueraltmo commented 7 months ago

Thanks in advance for your bug report!

What happened?

Pulsar failed when editing a markdown document.

I've been getting many crashes and bugs since 113, most of them related to TreeSitter, and to text-buffer.

Pulsar version

1.113.2024012615 arm64

Which OS does this happen on?

🍎 macOS

OS details

macOS 14.2.1

Which CPU architecture are you running this on?

Apple M1/M2

What steps are needed to reproduce this?

It's a bit random, but it always fails when writing markdown files. There are some actions that seem prone to trigger the crashes, like deleting text, and writing inline code.

I got those while running in safe mode.

I'm including two stack traces, one for each type of crash I'm getting, as they seem closely related.

Additional Information:

Stack Trace

Uncaught RuntimeError: Aborted(). Build with -sASSERTIONS for more info.

At /Applications/Pulsar.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1323

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/app.asar/vendor/web-tree-sitter/tree-sitter.js:267:29)
    at _abort (/app.asar/vendor/web-tree-sitter/tree-sitter.js:1217:21)
    at null.<anonymous> (wasm://wasm/000babee:0:118869)
    at ts_tree_edit_wasm (wasm://wasm/000babee:0:147738)
    at Tree.edit (/app.asar/vendor/web-tree-sitter/tree-sitter.js:2211:27)
    at LanguageLayer.handleTextChange (/app.asar/src/wasm-tree-sitter-language-mode.js:3291:17)
    at WASMTreeSitterLanguageMode.bufferDidChange (/app.asar/src/wasm-tree-sitter-language-mode.js:285:28)
    at TextBuffer.emitDidChangeEvent (/app.asar/node_modules/text-buffer/lib/text-buffer.js:956:25)
    at TextBuffer.applyChange (/app.asar/node_modules/text-buffer/lib/text-buffer.js:950:10)
    at TextBuffer.revertToCheckpoint (/app.asar/node_modules/text-buffer/lib/text-buffer.js:1387:14)
    at TextBuffer.transact (/app.asar/node_modules/text-buffer/lib/text-buffer.js:1322:12)
    at TextEditor.transact (/app.asar/src/text-editor.js:2467:24)
    at /app.asar/src/text-editor.js:1799:19
    at TextEditor.mergeSelections (/app.asar/src/text-editor.js:4053:20)
    at TextEditor.mergeIntersectingSelections (/app.asar/src/text-editor.js:4015:10)
    at TextEditor.mutateSelectedText (/app.asar/src/text-editor.js:1798:17)
    at TextEditor.backspace (/app.asar/src/text-editor.js:1786:17)
    at /app.asar/node_modules/underscore-plus/lib/underscore-plus.js:77:27)
    at /app.asar/src/register-default-commands.js:441:19)
    at /app.asar/src/register-default-commands.js:691:76
    at TextBuffer.transact (/app.asar/node_modules/text-buffer/lib/text-buffer.js:1320:16)
    at TextEditor.transact (/app.asar/src/text-editor.js:2467:24)
    at /app.asar/src/register-default-commands.js:691:13)
    at CommandRegistry.handleCommandEvent (/app.asar/src/command-registry.js:405:43)
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:617:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:408:22)
    at WindowEventHandler.handleDocumentKeyEvent (/app.asar/src/window-event-handler.js:153:34)

Commands

     -1:40.3.0 core:save (input.hidden-input)
 34x -1:27.4.0 core:backspace (input.hidden-input)
  2x -1:24.1.0 editor:newline (input.hidden-input)
 10x -1:20.3.0 core:backspace (input.hidden-input)
  2x -1:06.0 editor:newline (input.hidden-input)
  2x -1:02.3.0 core:move-up (input.hidden-input)
     -1:01.5.0 editor:move-to-end-of-screen-line (input.hidden-input)
  3x -0:27.2.0 core:backspace (input.hidden-input)

Stack Trace

Uncaught RuntimeError: Aborted(). Build with -sASSERTIONS for more info.

At /Applications/Pulsar.app/Contents/Resources/app.asar/vendor/web-tree-sitter/tree-sitter.js:267

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/app.asar/vendor/web-tree-sitter/tree-sitter.js:267:29)
    at _abort (/app.asar/vendor/web-tree-sitter/tree-sitter.js:1217:21)
    at null.<anonymous> (wasm://wasm/000babee:0:118389)
    at ts_query_captures_wasm (wasm://wasm/000babee:0:128728)
    at Query.captures (/app.asar/vendor/web-tree-sitter/tree-sitter.js:3026:27)
    at LanguageLayer.getSyntaxBoundaries (/app.asar/src/wasm-tree-sitter-language-mode.js:3123:43)
    at LayerHighlightIterator.seek (/app.asar/src/wasm-tree-sitter-language-mode.js:2754:55)
    at HighlightIterator.seek (/app.asar/src/wasm-tree-sitter-language-mode.js:2461:43)
    at ScreenLineBuilder.buildScreenLines (/app.asar/node_modules/text-buffer/lib/screen-line-builder.js:92:52)
    at DisplayLayer.getScreenLines (/app.asar/node_modules/text-buffer/lib/display-layer.js:637:35)
    at TextEditorComponent.queryScreenLinesToRender (/app.asar/src/text-editor-component.js:907:51)
    at TextEditorComponent.updateSyncBeforeMeasuringContent (/app.asar/src/text-editor-component.js:402:10)
    at TextEditorComponent.updateSync (/app.asar/src/text-editor-component.js:279:10)
    at /app.asar/src/text-editor-component.js:225:40
    at ViewRegistry.performDocumentUpdate (/app.asar/src/view-registry.js:264:7)

Commands

     -2:44.4.0 core:save (input.hidden-input)
  9x -2:43.2.0 core:move-down (input.hidden-input)
  3x -2:40.8.0 editor:newline (input.hidden-input)
     -2:38.3.0 core:backspace (input.hidden-input)
     -2:37.8.0 core:move-up (input.hidden-input)
     -2:37.6.0 editor:newline (input.hidden-input)
     -2:32.4.0 core:copy (input.hidden-input)
  2x -2:30.6.0 core:paste (input.hidden-input)
     -2:25.2.0 core:backspace (input.hidden-input)
     -2:24.3.0 core:move-up (input.hidden-input)
  2x -2:24 editor:newline (input.hidden-input)
     -2:23.3.0 core:move-up (input.hidden-input)
     -2:21.9.0 core:save (input.hidden-input)
     -1:54.4.0 core:backspace (input.hidden-input)
     -1:40.3.0 core:paste (input.hidden-input)
     -0:33.5.0 window:toggle-dev-tools (input.hidden-input)
savetheclocktower commented 7 months ago

I wrote an explanation of why this is happening in this comment. Right now, the most valuable thing a user could give me is a way to generate one of these failures (i.e., exact steps that will always produce a crash). I myself have had them happen once or twice over almost a year. If I can understand exactly why the failure happens, I can attempt to fix it.

In the meantime, if you get tired of the crashes, you can follow the steps in #878 to revert to the older markdown grammar.

Thanks for the report!

jqueraltmo commented 7 months ago

Ok, try this. I've tested it both in safe and normal mode, and after restarting my computer, and it consistently fails in the same way.

Open the linked file, go to the end of the first paragraph, where it says "relationships and symmetries.", and next to the dot (without spaces) write:

`a` `a` 

When pressing space after the second a, it crashes.

Note that I'm using a Spanish keyboard and this could affect the result.

Also, don't worry about the file's content, it's part of a free documentation project and already publicly available.

_index.md

savetheclocktower commented 7 months ago

Like this? Sadly, that's not crashing it for me:

Screenshot 2024-01-28 at 9 33 50 AM

In the unlikely case that your a is different from mine, I also tried copying and pasting your code block.

Daeraxa commented 7 months ago

I can't seem to replicate it with those steps annoyingly either, also with copying from GitHub. Is it possible that its somehow settings related? For example settings in brackets-matcher? Although I just tried it with auto-pair turned off and still no luck.

savetheclocktower commented 7 months ago

It wouldn't surprise me, except that @jqueraltmo is saying that the crash doesn't happen until after the space character, at which point the backticks are balanced.

jqueraltmo commented 7 months ago

I don't know what to say. This time it even crashed before, when writing the last backtick.

https://github.com/pulsar-edit/pulsar/assets/6584746/37f88d09-5050-40ee-b7a1-3a4bcdc83ce5

savetheclocktower commented 7 months ago

We'll keep iterating on this. @jqueraltmo, your help is greatly appreciated, but you should also feel free to add a scope-specific config to revert to the TextMate grammar as described in #878. The parser is the one committing the sins here and you shouldn't be the one who suffers.

Markdown is probably the flakiest parser we have as a bundled package. It's heartbreaking to me, because it'd never crashed on me in many months of being its only user, but apparently the Markdown I write is not as complex as the Markdown that exists out in the universe.

The fact that it feels free to sprinkle asserts throughout its external C++ scanner means that its author apparently did not envision it would be used in an editor environment where “give up and exit” isn't a realistic option. I'm going to do whatever I can to get us past the blockers preventing us from using this newer parser.

jqueraltmo commented 7 months ago

Is there any additional test or configuration I can try to help pinpoint the bug better?

savetheclocktower commented 7 months ago

If you can identify another reduced test case which fails for you, please let us know. I know I wasn't able to reproduce this example, but I have been able to reproduce some of the reported issues for the parser.

Right now, my feeling is that I'd have to become the maintainer of this weird parser (a job I'm not qualified for) in order to make it reliable enough for everyone to use. But failing that, I could at least try to address the most common crash paths to give users some temporary relief.

jqueraltmo commented 7 months ago

This may be a good clue: I've just disabled "Autocomplete Brackets" in the "Bracket Matcher" package configuration, and now Pulsar seems a lot more stable. For example, I can't reproduce my previous test case with this configuration.

savetheclocktower commented 7 months ago

I have that setting enabled all the time, so this only deepens the mystery! Up is down, red is green, shoes are hats.

jqueraltmo commented 7 months ago

It also has something to do with the keyboard layout. I reactivated bracket matching, and configured my keyboard as it had an English layout. There were no crash. As soon as I tried with the Spanish layout, it got back.

In a Spanish layout, a backtick is used for some letters like Ă . Then, to write a backtick, you have to press ` and then space. Between the two keystrokes, the system draws a highlighted backtick, waiting for you to decide which final character are you writing.

I think it's in this state that problems arise, specially when writing the closing backtick of an expression.

Daeraxa commented 7 months ago

I wouldn't be surprised, I've not had good experiences with Electron and dead keys before...

savetheclocktower commented 7 months ago

I think it's in this state that problems arise, specially when writing the closing backtick of an expression.

That would align with what I know about another documented crash in which the user was composing Japanese text and was doing something with combining characters. It's a clue, at least.

JackDougherty commented 7 months ago

In case this helps diagnose the issue, I also experienced frequent crashes while typing plain old Markdown (see screenshot), but have had no crashes for several days after I followed suggestion by @jqueraltmo and disabled "Autocomplete Brackets" in the "Bracket Matcher" package configuration

Mac OS 13.6.3 Apple M1 Pulsar 1.113.2024013115 US English keyboard

Screenshot 2024-02-05 at 2 17 24 PM

savetheclocktower commented 7 months ago

That's bizarre, since I was the one schmuck using this grammar for months before we added it to core and this never happened to me despite the fact that I've got “Autocomplete Brackets” enabled.

@JackDougherty, you might want to try the experimental replacement package that I'm hoping will solve all these problems. At the very least it ought to crash far less often.

xansec commented 5 months ago

Just wanted to note that I run into this frequently when typing Japanese into .mdx files.

savetheclocktower commented 5 months ago

Just wanted to note that I run into this frequently when typing Japanese into .mdx files.

Yeah, that's the consensus, @xansec. I hope to replace the current grammar with the one in the experimental replacement package in time for this month's release.