d-language-server / dls

A Language Server implementation for D
http://dls.dub.pm
106 stars 15 forks source link

Poor behavior on malformed dub package description #69

Open AsumFace opened 4 years ago

AsumFace commented 4 years ago

The following are the outputs gathered from vscode, I make the report in this repo because I don't think this is a problem with the extension itself.

Output when dub.json or dub.sdl is completely empty, this should give a meaningful error message instead:

[Error - 23:07:44] Server initialization failed.
  Message: Internal error
  Code: -32603 
object.Exception@/usr/lib/ldc2/1.17/include/d/std/stdio.d(1074): rawRead must take a non-empty buffer
----------------
stdio.d:1074 @safe ubyte[] std.stdio.File.rawRead!(ubyte).rawRead(ubyte[]) [0x55dfc98d7f9c]
file.d:46 [0x55dfc9b7a8bc]
file.d:42 [0x55dfc9b7a83e]
io.d:40 [0x55dfc9beef65]
package_.d:164 [0x55dfc9bb3b0c]
packagemanager.d:201 [0x55dfc9bb986f]
project.d:66 [0x55dfc9bc66ac]
dub.d:375 [0x55dfc9b1f3a2]
dub.d:367 [0x55dfc9b1f2cb]
symbol_tool.d:1489 [0x55dfc97278c0]
symbol_tool.d:559 [0x55dfc9726953]
symbol_tool.d:532 [0x55dfc9726808]
general.d:83 [0x55dfc976705f]
handlers.d:79 [0x55dfc9827c86]
server.d:251 [0x55dfc97b1c0b]
server.d:328 [0x55dfc97b16f5]
server.d:178 [0x55dfc97b1552]
??:? fiber_entryPoint [0x7f299c25a261]

Output when dub.json contains a single space:

[Info  - 23:10:18] Connection to server got closed. Server will restart.
[Info  - 23:10:18] Connection to server got closed. Server will restart.
[Info  - 23:10:18] Connection to server got closed. Server will restart.
[Info  - 23:10:18] Connection to server got closed. Server will restart.
[Error - 23:10:18] Connection to server got closed. Server will not be restarted.

The server continues to hog two cores even after vscode is closed.

Output when dub.sdl contains a single space and dub.json does not exist:

[Error - 23:13:34] Server initialization failed.
  Message: Internal error
  Code: -32603 
object.Exception@/XXX/.dub/packages/dub-1.17.0/dub/source/dub/recipe/sdl.d(61): /XXX/dub.sdl(0): Error: The package "name" field is missing or empty.
----------------
sdl.d:358 [0x5571e7cb0904]
sdl.d:61 [0x5571e7cb02ce]
sdl.d:25 [0x5571e7cafde0]
io.d:75 [0x5571e7ca11d0]
io.d:43 [0x5571e7ca1039]
package_.d:164 [0x5571e7c65b0c]
packagemanager.d:201 [0x5571e7c6b86f]
project.d:66 [0x5571e7c786ac]
dub.d:375 [0x5571e7bd13a2]
dub.d:367 [0x5571e7bd12cb]
symbol_tool.d:1489 [0x5571e77d98c0]
symbol_tool.d:559 [0x5571e77d8953]
symbol_tool.d:532 [0x5571e77d8808]
general.d:83 [0x5571e781905f]
handlers.d:79 [0x5571e78d9c86]
server.d:251 [0x5571e7863c0b]
server.d:328 [0x5571e78636f5]
server.d:178 [0x5571e7863552]
??:? fiber_entryPoint [0x7fb91f1b4261]

I consider the error message to be acceptable and useful. The stack trace makes it look more dramatic than it is, it should probably be omitted for user-originated mistakes.

LaurentTreguier commented 4 years ago

This seems to come from Dub. DLS uses Dub as a library to parse dub.json or dub.sdl, and trying to run dub directly with the same malformed dub files result in the same errors. The second erroring, with no stacktrace, is due to an AssertError, while the others are due to Exceptions, which is why DLS sends back the stacktrace instead of directly crashing.

I can ignore exceptions coming from malformed files, however maybe the assertion error should be patched in Dub directly.

AsumFace commented 4 years ago

Thanks for looking into this, I downloaded the newly released version 1.19 of dub and the assert does not trigger anymore (although i'm getting other errors randomly). It appears that the binary distribution of dub behaves differently from the locally built version, the binary distribution detects that the json is malformed and outputs an error accordingly.

LaurentTreguier commented 4 years ago

Using the distributed binary from dlang.org, it does exit with an AssertError when dub.json only contains a space, on macOS. I'll check on Windows/Linux as well