hediet / vscode-debug-visualizer

An extension for VS Code that visualizes data during debugging.
https://marketplace.visualstudio.com/items?itemName=hediet.debug-visualizer
GNU General Public License v3.0
7.9k stars 407 forks source link

request: more visibility into JSON parsing errors #78

Open phrohdoh opened 4 years ago

phrohdoh commented 4 years ago

With this (completely valid and schema-compliant (AstTreeVisualizationData), AFAICT) JSON

{"kind":{"ast":true,"tree":true,"text":true},"root":{"items":[{"text":"exploding-barrel:"}],"children":[{"items":[{"text":"Tooltip:"}],"children":[],"span":{"start":18,"length":13},"segment":"todo"},{"items":[{"text":"Name: barrels"}],"children":[],"span":{"start":31,"length":22},"segment":"todo"},{"items":[{"text":"Health:"}],"children":[],"span":{"start":53,"length":12},"segment":"todo"},{"items":[{"text":"HP: 5"}],"children":[],"span":{"start":65,"length":14},"segment":"todo"},{"items":[{"text":"Explodes:"}],"children":[],"span":{"start":79,"length":14},"segment":"todo"},{"items":[{"text":"Weapon: large-barrel-explode"}],"children":[],"span":{"start":93,"length":37},"segment":"todo"},{"items":[{"text":"MapEditorData:"}],"children":[],"span":{"start":130,"length":19},"segment":"todo"},{"items":[{"text":"Categories: props, dangerous-props"}],"children":[],"span":{"start":149,"length":43},"segment":"todo"}],"span":{"start":0,"length":193},"segment":"doc-root"},"text":"exploding-barrel:\n    Tooltip:\n        Name: barrels\n    Health:\n        HP: 5\n    Explodes:\n        Weapon: large-barrel-explode\n    MapEditorData:\n        Categories: props, dangerous-props\n"}

I am getting the following parse error:

Screen Shot 2020-08-30 at 8 36 08 AM

Given my JSON is valid, I'm just stuck. I don't know what to change (and why) to give the visualizer what it wants.

Any insight and ideas on improving this greatly appreciated!

hediet commented 4 years ago

It looks like it tries to parse it as string ("{") and then encounters the k.

What is the difference to https://github.com/hediet/vscode-debug-visualizer/pull/75?

hediet commented 4 years ago

Also, to test the schema, you can use the playground.

hediet commented 4 years ago

My guess is that lldb shortens long strings. The debug visualizer extension is trying out various ways how to parse the string (it tries to remove any surrounding quotation mark), but only reports the last one. So there might be a different json parse error. Can to copy the entire text of the error message and paste it here?

phrohdoh commented 4 years ago

Yeah, it looks like lldb truncates 🤦.

Could not parse evaluation result as JSON:

Unexpected token k in JSON at position 3

Evaluation result was:
"{"kind":{"ast":true,"tree":true,"text":true},"root":{"items":[{"text":"exploding-barrel:"}],"children":[{"items":[{"text":"Tooltip:"}],"children":[],"span":{"start":18,"length":13},"segment":"todo"},{"items":[{"text":"Name: barrels"}],"children":[],"span":{"start":31,"length":22},"segment":"todo"},{"items":[{"text":"Health:"}],"children":[],"span":{"start":53,"length":12},"segment":"todo"},{"items":[{"text":"HP: 5"}],"children":[],"span":{"start":65,"length":14},"segment":"todo"},{"items":[{"text":"Explodes:"}],"children":[],"span":{"start":79,"length":14},"segment":"todo"},{"items":[{"text":"Weapon: large-barrel-explode"}],"children":[],"span":{"start":93,"length":37},"segment":"todo"},{"items":[{"text":"MapEditorData:"}],"children":[],"span":{"start":130,"length":19},"segment":"todo"},{"items":[{"text":"Categories: props, dangerous-props"}],"children":[],"span":{"start":149,"length":43},"segment":"todo"}],"span":{"start":0,"length":193},"segment":"doc-root"},"text":"exploding-barrel:..."

Used debug adapter: lldb
phrohdoh commented 4 years ago

https://stackoverflow.com/a/41600000 may be what we want in this case.

hediet commented 4 years ago

Or this one: https://stackoverflow.com/questions/31402092/print-long-string-in-xcode-6-debugging-console

hediet commented 4 years ago

https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#launching-a-new-process

I think initCommands can be used to configure these things.

phrohdoh commented 4 years ago

Setting target.max-string-summary-length to 10000 (via initCommands) seems to make no difference, the string is still truncated (with ... appended) at the exact same position.

edit: confirmed that max-string-summary-length is indeed being set to 10000 (via initCommands) by executing settings show target.max-string-summary-length in VSCode's debug console, which prints target.max-string-summary-length (int) = 10000.

hediet commented 4 years ago

Your string is truncated after exactly 1000 chars. Maybe you can reverse search a setting that has that value.

hediet commented 4 years ago

This article also uses target.max-string-summary-length. Is the watch windows also truncating the string? What about the debug console?

phrohdoh commented 4 years ago

AFAIK the watch viewlet and debug console are driven by the debug adapter. Yes, both of them display the truncated value.

I do not have any lldb settings with the value 1000 (confirmed by running settings show and searching over the result).

hediet commented 4 years ago

AFAIK the watch viewlet and debug console are driven by the debug adapter.

Yes, this extension is driven too by the debug adapter. However, the watch viewlet uses the watch context, the debug console the repl context, and this extension by default also the repl context (that you overwrote with watch).

hediet commented 4 years ago

I do not have any lldb settings with the value 1000 (confirmed by running settings show and searching over the result).

This is unfortunate. If you make it work in the repl context with long strings (maybe there is some special formatting argument), I could extend the json parsing logic to deal with lldb outputs.

If lldb has no way to output long strings, this extension cannot do much.

phrohdoh commented 4 years ago

This is indeed unfortunate. Thank you for your help and time!

hediet commented 4 years ago

I think your main point is still valid. The error reporting is still not good.