-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
nvim-dap will JSON encode very large integers in scientific notation #1004
Comments
related upstream dart DAP server bug, although I think we need both to be fixed. That bug is to ensure that our threadIds never exceed 2^53, which lua doubles could not accurately track, and this bug is to ensure that below that threshold we never JSON encode ints to scientific notation. |
FYI this is my custom json encoding logic: https://github.com/mfussenegger/nvim-dap/compare/master...christopherfujino:nvim-dap:dev?expand=1 |
Converting them to a string could break other debug adapters that expect a number. For example in Haskell: print $ (decode "{\"threadId\": 3053700806959403}" :: Maybe Foo)
-- Just (Foo {threadId = 3053700806959403})
print $ (decode "{\"threadId\": 3.0537008069594e+15}" :: Maybe Foo)
-- Just (Foo {threadId = 3053700806959400})
print $ (decode "{\"threadId\": \"3053700806959403\"}" :: Maybe Foo)
-- Nothing So this is not an option. I created an issue in the debug adapter protocol repository to clarify the allowed ranges: microsoft/debug-adapter-protocol#422 Depending on that we may need some way in Neovim to configure the number precision. There is functionality in cjson, but it's currently disabled/not exposed: |
No, I'm not wrapping the int in quotes. I'm just creating a string for the overall json message. |
That having been said, it would be great if we could configure this and didn't have to do it in lua :) https://github.com/neovim/neovim/blob/9b5f58185e1ff0597c7e95b7205d9ec11be1848c/src/cjson/lua_cjson.c#L358-L365 |
Closing this here. I don't intend to add an alternative json encoder/decoder. A fix would need to go into neovim core: neovim/neovim#24532 |
Debug adapter definition and debug configuration
Debug adapter version
d17d1bb
Steps to Reproduce
Have the server send a request with an integer large enough that lua's internal
tostring()
implementation would return a string in scientific notation, such as:My exact case was my dart debug-adapter server sent the following body string:
While lua doubles have enough precision to store this number accurately,
tostring()
will use scientific notation, for convenience. Thus, when the nvim-dap client re-encodes this ID number to send a future request to the server, such as this:The server throws an exception:
TL;DR the server crashes because it receives a double where an int was expected.
The only solution I can think of to fix this is to write a custom json encoder that will test if numbers are integers, and if so ensure they are stringified as such to ensure no loss of precision (even if the server were to be more lax, if you notice in this example, two decimal points of precision are lost by using scientific notation).
To unblock myself, I will write a custom lua encoder. @mfussenegger I'm curious whether you would be interested in upstreaming it, or if this is such a nice bug that I should just maintain my own fork.
Expected Result
Breakpoints can be hit without the server crashing.
Actual Result
See above, the server receives scientific notation which it interprets as a double, and a cast to int fails.
The text was updated successfully, but these errors were encountered: