Cannot debug cursive crate

Guys, I have a come up against a problem which is most likely very easy to fix but I have no idea how to do it. I'm trying to debug my "program" and I'm getting:

thread 'main' panicked at 'called Result::unwrap()on anErr value: Custom { kind: Other, error: "$TERM is unset. Cannot initialize ncurses interface." }',

How to set the TERM variable?
Thanks

Which OS?

Ubuntu

Your terminal really should be setting the TERM variable. In any case you can set it with

export TERM=xterm

Hey, thanks for the answer. Will check that now!

OK, so, didn't help. I am doing something wrong obviously.
I've executed the command you provided in VS Code terminal and started debugging. Same error.
What am I doing wrong?

If you are using the rust-analyzer and LLDB plugins for VS Code, you can configure them to run your program in a terminal by adding something like this to your settings.json:

    "rust-analyzer.debug.engineSettings": {
        "lldb": { "terminal": "external" }
    }

You can search for "terminal" in the VS Code settings tab for some other possible configurations.

@mbrubeck Hi and thanks for trying to help.
I do have a launch.json in my project. So I did paste the configuration you posted. No luck. Still the same error. Or do I have to create somehow that settings.json?

I don't see a way to set this LLDB option in launch.json.

To add it to settings.json:

  1. Open the VS Code "Settings" tab.
  2. Open the "Workspace" tab to edit settings for the current project only.
  3. Find the LLDB › Launch: Terminal setting.
  4. Change the value from "console" to "external". ("internal" might also work.)

[Edit] Finally I found it. But I'm getting now:

Still getting info about TERM not being set.
Would you know what to do with it?
Thanks

In launch.json you can also just set the environment variable. For a configuration you can pass it an env variable and do something like ”env”:{“TERM”:”xterm”}. See this Stack Overflow answer for some more details

Hi and thank you for your reply. After setting that var in launch.json I'm getting: See screenshot.
Thanks

Hmm. It looks like the VS Code extension is redirecting the program's stdio to the terminal window, but not actually giving the program full access to the terminal's TTY.

You could instead launch the program manually in an external terminal, and then add an lldb configuration in launch.json to attach to the running process.

can you post your launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'ac1'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=ac1",
                    "--package=ac1"
                ],
                "filter": {
                    "name": "ac1",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}",
            "env": {"TERM" : "ncurses","RUST_BACKTRACE":"full"}
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in executable 'ac1'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--bin=ac1",
                    "--package=ac1"
                ],
                "filter": {
                    "name": "ac1",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}",
        }
    ]
}

Try adding "externalConsole": true like so

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug executable 'ac1'",
            "cargo": {
                "args": [
                    "build",
                    "--bin=ac1",
                    "--package=ac1"
                ],
                "filter": {
                    "name": "ac1",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}",
            "externalConsole": true,
            "env": {"TERM" : "ncurses","RUST_BACKTRACE":"full"}
        },
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in executable 'ac1'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--bin=ac1",
                    "--package=ac1"
                ],
                "filter": {
                    "name": "ac1",
                    "kind": "bin"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}",
        }
    ]
}
1 Like

Unfortunately didn't help. I'm actually getting info from "intelliSense" that externalConsole is not allowed property

what about this instead

      "console": "externalTerminal",

Nope... Same thing... panics.

Instead of TERM=ncurses. Did you try TERM=xterm