Skip to content

fix: line authoring crashes when dom Element cannot be removed. #891

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

Merged
merged 2 commits into from
Apr 1, 2025

Conversation

GollyTicker
Copy link
Contributor

This bug has been here since the very beginning when I implemented the line authoring into obsidian-git.

For unknown reasons, somtimes the dom.remove() fails and an exception is bubbled up - which makes the line authoring and afaik the whole plugin crash. Then the line authoring suddenly disappears and can't be brought back without a restart. It's hard to consistently reproduce it and I didn't brother too much with it back then - but this simply try and catch should fix it sufficiently.

Whenever I come across this error, I have to restart obsidian - but this isn't a good workaround for users who don't know what's happening. They'll probably just abandon this plugin or whatever.

Do you have any questions?

@Vinzent03
Copy link
Owner

Do you know how the error looks like? And I think it's better to not just silently ignore the error, but at least log it to console. This should make it easier to debug or detect other issues because of this error in the future.

@GollyTicker
Copy link
Contributor Author

GollyTicker commented Mar 31, 2025 via email

@GollyTicker
Copy link
Contributor Author

Here is the stacktrace when an error happend.

app.js:1 TypeError: Cannot read properties of null (reading 'remove')
    at lp.destroy (plugin:obsidian-git:179:6373)
    at e.setMarkers (app.js:1:520587)
    at e.destroy (app.js:1:520791)
    at e.destroy (app.js:1:519730)
    at e.updateGutters (app.js:1:516057)
    at e.update (app.js:1:514220)
    at e.update (app.js:1:352236)
    at e.updatePlugins (app.js:1:458752)
    at e.update (app.js:1:456799)
    at e.dispatchTransactions (app.js:1:453296)
Gi @ app.js:1

@Vinzent03
Copy link
Owner

So the error is that dom is null. Isn't it better to just check if it's null or not than catching all errors? The if check is always true for a null value, so I would add that check to the existing if-clause of find the reason for dom being null.

@GollyTicker
Copy link
Contributor Author

I added a check for null now. I'll keep the try catch and the warning, ok?

@Vinzent03
Copy link
Owner

Hmm no I would remove the try-catch and just keep the null check. I'm not aware of any reasonable errors that can happen there that should be caught. If the remove fails, it might have a good reason and should be caught higher up in the call tack.

@GollyTicker
Copy link
Contributor Author

Changed.

@Vinzent03 Vinzent03 merged commit 2d2ebfd into Vinzent03:master Apr 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants