Don't crash on document URIs with an invalid scheme#4127
Conversation
A client can send a textDocument message whose URI uses a scheme Ruby's URI() parser rejects, such as the `_claude_fs_right:` scheme the Claude Code extension registers for inline diffs. BaseServer#start only rescued Store::NonExistingDocumentError, so URI::InvalidURIError escaped the reader loop and crashed the server. Rescue URI::Error there as well so the message falls through to normal dispatch. Closes Shopify#4067
|
Thank you for the patch, but the question in the issue remain. When and why is sending those URIs? We know it is claude code, but when does it send that, and why? |
|
The schemes come from Claude Code's inline diff feature. When it proposes an edit it opens a native diff whose two sides are virtual documents under |
Motivation
Closes #4067. A client can send a
textDocumentmessage whose URI uses a scheme Ruby'sURI()parser rejects, which crashes the server and drops the connection. The Claude Code extension does this with its_claude_fs_right:and_claude_fs_left:inline-diff schemes, where the leading underscore is invalid under RFC 3986.BaseServer#startwraps theURI(uri)call only inrescue Store::NonExistingDocumentError, soURI::InvalidURIErrorescapes the reader loop.Implementation
Rescue
URI::Errornext to the existingStore::NonExistingDocumentErrorrescue. The message then continues to normal dispatch, whereprocess_messagealready returns an error response for requests and logs notifications, so a URI Ruby cannot parse no longer crashes the reader loop.Automated Tests
Added a test that drives
startwith an invalid-scheme document URI and asserts the server stays up and still answers the request with an error.