vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.42k stars 237 forks source link

support case of cargo outputting empty lines #983

Closed Davidster closed 10 months ago

Davidster commented 10 months ago

When trying to debug a unit test from the parry rust crate, I got an error in the codelldb vscode extension. Here was my launch config:

{
  "type": "lldb",
  "request": "launch",
  "name": "Debug unit tests in library 'parry3d'",
  "cargo": {
    "args": [
      "test",
      "--package=parry3d"
    ],
    "filter": {
      "name": "parry3d",
      "kind": "lib"
    }
  },
  "args": [],
  "cwd": "${workspaceFolder}"
}

and here was the error:

Running `cargo test --package=parry3d --message-format=json`...
Error: Cargo invocation failed.
    at t.Cargo.getCargoArtifacts (/home/david/.vscode/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:15379)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at Object.open (/home/david/.vscode/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:13689)
Caused by: Error: Could not parse JSON: ""
    at Interface.<anonymous> (/home/david/.vscode/extensions/vadimcn.vscode-lldb-1.9.2/extension.js:1:16948)
    at Interface.emit (node:events:513:28)
    at Interface._onLine (node:readline:491:10)
    at Interface._normalWrite (node:readline:665:12)
    at Socket.ondata (node:readline:272:10)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

I suspect this is caused by the new lines added at the end of the message but I'm not sure

vadimcn commented 10 months ago

The cargo command is supposed to build targets only, not run them. See discussion here.

Davidster commented 10 months ago

Oh I see, so it's a problem with the way the launch configs are auto-generated. Is that process managed by the extension or by vscode itself?

vadimcn commented 10 months ago

The generated config should have included --no-run. Are you sure it was not modified afterwards?

Davidster commented 10 months ago

it seems that you were right and that this was caused by me having removed the "--no-run" argument. thanks for the help!

what would you think about adding a hint in the error message:

let hint = line.trim() === "" ? ". Did you remove the --no-run argument?" : "";
reject(new ErrorWithCause(`Could not parse JSON: "${line}"${hint}`, { cause: err }));