Skip to content

Don’t crash sourcekit-lsp if a known message is missing a field #1154

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

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 29, 2024

Previously, we fatalErroring when JSONDecoder failed to decode a message from the client. Instead of crashing, try recovering from such invalid messages as best as possible. If we know that the state might have gotten out of sync with the client, show a notification message to the user, asking them to file an issue.

rdar://112991102

@ahoppen ahoppen requested a review from bnbarham March 29, 2024 12:53
@ahoppen ahoppen requested a review from benlangmuir as a code owner March 29, 2024 12:53
@ahoppen
Copy link
Member Author

ahoppen commented Mar 29, 2024

@swift-ci Please test

case .unknown:
// We don't know what has gone wrong. This could be any level of badness. Inform the user about it.
logger.fault("ignoring unknown message")
sendMessageDecodingErrorNotificationToClient(message: "sourcekit-lsp failed to decode a message")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you purposefully making this slightly different to the catch case so that we know the difference from eg. a screenshot?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

// We failed to parse the message header. There isn't really much we can do to recover because we lost our
// anchor in the stream where new messages start. Crashing and letting ourselves be restarted by the client is
// probably the best option.
sendMessageDecodingErrorNotificationToClient(message: "Failed to find next message in connection to editor.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The . will cause a .. as sendMessageDecodingErrorNotificationToClient adds a . itself

@ahoppen ahoppen force-pushed the ahoppen/dont-crash-if-message-has-missing-field branch from 5527188 to eb28054 Compare March 29, 2024 22:17
@ahoppen
Copy link
Member Author

ahoppen commented Mar 29, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Mar 29, 2024

@swift-ci Please test Windows

} catch {
// We don't know what has gone wrong. This could be any level of badness. Inform the user about it and ignore the
// message.
logger.fault("ignoring unknown message")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed one :)

Previously, we `fatalError`ing when `JSONDecoder` failed to decode a message from the client. Instead of crashing, try recovering from such invalid messages as best as possible. If we know that the state might  have gotten out of sync with the client, show a notification message to the user, asking them to file an issue.

rdar://112991102
@ahoppen ahoppen force-pushed the ahoppen/dont-crash-if-message-has-missing-field branch from eb28054 to be42621 Compare April 2, 2024 05:50
@ahoppen
Copy link
Member Author

ahoppen commented Apr 2, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Apr 2, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 3e51f70 into swiftlang:main Apr 2, 2024
@ahoppen ahoppen deleted the ahoppen/dont-crash-if-message-has-missing-field branch April 2, 2024 22:42
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