Internal Error -32603 when source files have non-ASCII characters in their path or name
Describe the bug
The LSPs emits a stream of Internal Error -32603 for the files with URI-escaped characters in the file name supplied by VS Code,
e.g. when a file is named hôpital.clj.
The related error messages that pop up in VS Code are many, some examples are Request textDocument/semanticTokens/range failed., Request textDocument/semanticTokens/full failed. and Request textDocument/documentSymbol failed.
To Reproduce Steps to reproduce the behavior:
- Create a Clojure file with a non-ASCII character in its name or path, e.g. 'hôpital.clj'
- Open the file in VS Code
- Notice the errors popping up from the Clojure LSP (via Calva)
Expected behavior Correct translation from the VS Code supplied URI with URI-escaped characters to the corresponding file name and thus no errors when running LSP on that file.
Screenshots Not applicable
Log - client server
[Trace - 10:55:48 AM] Sending notification 'textDocument/didOpen'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj", "languageId": "clojure", "version": 1, "text": "" } }
[Trace - 10:55:48 AM] Sending request 'textDocument/documentSymbol - (143)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" } }
[Trace - 10:55:48 AM] Sending request 'textDocument/semanticTokens/full - (144)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" } }
[Trace - 10:55:48 AM] Sending request 'textDocument/codeAction - (145)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" }, "range": { "start": { "line": 0, "character": 0 }, "end": { "line": 0, "character": 0 } }, "context": { "diagnostics": [], "triggerKind": 2 } }
[Trace - 10:55:48 AM] Received response 'textDocument/documentSymbol - (143)' in 2ms. Request failed: Internal error (-32603). Error data: { "id": 143, "method": "textDocument/documentSymbol" }
[Error - 10:55:48 AM] Request textDocument/documentSymbol failed. Message: Internal error Code: -32603 [object Object] [Trace - 10:55:48 AM] Received response 'textDocument/semanticTokens/full - (144)' in 3ms. Request failed: Internal error (-32603). Error data: { "id": 144, "method": "textDocument/semanticTokens/full" }
[Error - 10:55:48 AM] Request textDocument/semanticTokens/full failed. Message: Internal error Code: -32603 [object Object] [Trace - 10:55:48 AM] Received response 'textDocument/codeAction - (145)' in 4ms. Request failed: Internal error (-32603). Error data: { "id": 145, "method": "textDocument/codeAction" }
[Error - 10:55:48 AM] Request textDocument/codeAction failed. Message: Internal error Code: -32603 [object Object] [Trace - 10:55:48 AM] Received response 'textDocument/documentHighlight - (142)' in 4ms. Result: [ { "range": { "start": { "line": 0, "character": 4 }, "end": { "line": 0, "character": 50 } } } ]
[Trace - 10:55:48 AM] Sending request 'textDocument/semanticTokens/range - (146)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" }, "range": { "start": { "line": 0, "character": 0 }, "end": { "line": 0, "character": 0 } } }
[Trace - 10:55:48 AM] Received response 'textDocument/semanticTokens/range - (146)' in 1ms. Request failed: Internal error (-32603). Error data: { "id": 146, "method": "textDocument/semanticTokens/range" }
[Error - 10:55:48 AM] Request textDocument/semanticTokens/range failed. Message: Internal error Code: -32603 [object Object] [Trace - 10:55:48 AM] Sending request 'textDocument/documentSymbol - (147)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" } }
[Trace - 10:55:48 AM] Received response 'textDocument/documentSymbol - (147)' in 1ms. Request failed: Internal error (-32603). Error data: { "id": 147, "method": "textDocument/documentSymbol" }
[Error - 10:55:48 AM] Request textDocument/documentSymbol failed. Message: Internal error Code: -32603 [object Object] [Trace - 10:55:48 AM] Sending request 'textDocument/foldingRange - (148)'. Params: { "textDocument": { "uri": "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj" } }
[Trace - 10:55:48 AM] Received response 'textDocument/foldingRange - (148)' in 1ms. Result: []
Log - clojure-lsp
This is an excerpt, you will see the same exception for all the messages:
2024-07-18T08:55:48.387Z DEBUG [clojure-lsp.server:55] - [Trace - 2024-07-18T08:55:48.387Z] Received request 'textDocument/documentSymbol - (147)'
Params: {
"text-document" : {
"uri" : "file:///home/foo/src/example/test/clj/example/h%C3%B4pital.clj"
}
}
2024-07-18T08:55:48.387Z ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 147, :method "textDocument/documentSymbol"}
com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine PlatformThreads.java: 872
com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine PlatformThreads.java: 896
java.util.concurrent.ForkJoinWorkerThread.run ForkJoinWorkerThread.java: 188
java.util.concurrent.ForkJoinPool.runWorker ForkJoinPool.java: 1808
java.util.concurrent.ForkJoinPool.scan ForkJoinPool.java: 1843
java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec ForkJoinPool.java: 1312
java.util.concurrent.ForkJoinTask.doExec ForkJoinTask.java: 387
java.util.concurrent.CompletableFuture$AsyncSupply.exec CompletableFuture.java: 1760
java.util.concurrent.CompletableFuture$AsyncSupply.run CompletableFuture.java: 1768
promesa.util.Supplier/get util.cljc: 34
promesa.exec/wrap-bindings/fn exec.cljc: 163
clojure-lsp.server/fn/fn server.clj: 346
clojure-lsp.handlers/document-symbol handlers.clj: 293
clojure-lsp.handlers/skip-feature-for-uri? handlers.clj: 142
clojure-lsp.shared/uri->filename shared.clj: 223
clojure-lsp.shared/uri-obj->filepath shared.clj: 179
java.nio.file.Paths.get Paths.java: 98
java.nio.file.Path.of Path.java: 204
sun.nio.fs.UnixFileSystemProvider.getPath UnixFileSystemProvider.java: 125
sun.nio.fs.UnixUriUtils.fromUri UnixUriUtils.java: 88
java.lang.IllegalArgumentException: Bad escape
2024-07-18T08:55:48.387Z DEBUG [clojure-lsp.server:55] - [Trace - 2024-07-18T08:55:48.387Z] Sending response 'textDocument/documentSymbol - (147)'. Request took 0ms. Request failed: Internal error (-32603).
Error data: {
"id" : 147,
"method" : "textDocument/documentSymbol"
}
User details (please complete the following information):
- OS: Ubuntu Linux on Windows 10
- Editor VSCode (Calva version used: v2.0.467)
- Version: clojure-lsp version used: 2024.04.22-11.50.26
Additional context
The bug seems to be in the function, clojure-lsp.shared/uri-obj->filepath in shared.clj where the conversion happens via .toString.
The problem happens because we use java URI here for a lot of features and it seems java URI doesn't support non-ascii chars. Not sure the best way to fix that