-
-
Notifications
You must be signed in to change notification settings - Fork 35
prevent crash in locStart/locEnd when node location is undefined #864
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
base: main
Are you sure you want to change the base?
Conversation
Prettier's formatWithCursor can crash if a node is missing a valid `location` object. This patch adds null-safe checks and fallback handling in `locStart` and `locEnd` to avoid TypeErrors and ensure graceful degradation. Signed-off-by: Toni Förster <[email protected]>
Can you give me a text XML file where this happens? I have not found an example. If there is a test you could add, that would be great. I don't want to be needlessly defensive here. |
@kddnewton no worries. It happens with this test file, with my Prettier extension for Nova. The error message I get can be found in the issue in the first comment: stonerl/nova-prettier-extension#41 (comment) |
It could also be me implementing |
I don't think you're doing it wrong, but is it possible you're using an earlier version of the plugin? I cannot get it to crash with the latest version. |
I'm using the I currently apply this patch when installing all npm packages, and it circumvents the error and allows formatting XML files. This could be something that happens only in combination with Nova. I don't mind if this patch won't go into upstream, I can keep it as part of my extension. |
I think I might know what's going on here. Nova is using Apple's JavaScript Core engine. I assume you're using node.js for testing? It could be that this is just a platform specific error. |
I don't think so, if I run this in bun or safari it passes. I would be shocked if this had anything to do with the runtime as it's a logic error. Are you 100% sure you're on the latest version? |
Pretty sure:
|
Just an update. I ran into the same error while implementing |
Prettier's formatWithCursor can crash if a node is missing a valid
location
object.This patch adds null-safe checks and fallback handling in
locStart
andlocEnd
to avoid TypeErrors and ensure graceful degradation.