Repository navigation
Description
Describe the bug
Problem arises from a change in #6584:
Trying to launch interactive nushell via the CodeLLDB VS Code extension causes a panic on this line.
It appears that fd 0 is a valid tty and the atty crate is reporting the same thing. I don't fully grasp how we can deal with the other error cases vaguely described in https://man7.org/linux/man-pages/man3/tcgetpgrp.3.html
How to reproduce
Install VS code and the CodeLLDB VS Code extension
Setup the launch.json automatically based on the cargo workspace.
Launch the nu executable via the Debugger (F5).
Reproducibility notes: both on Ubuntu standalone and with WSL2 I was able to cause this crash (for the external and internal terminal option in the launch.json config).
Expected behavior
Any failure to get those process groups should not kill the application. Having the option to debug nushell interactively that way is valuable (even if we might deviate from some regular behavior in a documented way to achieve that).
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.69.2 |
| branch | alias_fix |
| commit_hash | f058460 |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.63.0 (4b91a6ea7 2022-08-08) |
| rust_channel | 1.63.0-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.63.0 (fd9c4297c 2022-07-01) |
| pkg_version | 0.69.2 |
| build_time | 2022-10-14 21:46:53 +02:00 |
| build_rust_channel | debug |
| features | default, trash, which, zip |
| installed_plugins |
Additional context
Launching gdb target/debug/nu was not picking up this panic if I get this correctly (but my gdb foo is not strong enough to properly launch nu in a separate terminal while being attached from the start.) Regular late attaching with gdb -p <nu pid> was not causing unexpected problems.

Activity
fdncred commentedon Oct 17, 2022
@sholderbach is this still a problem even after the most recent changes by unrelentingtech #6779?
sholderbach commentedon Oct 17, 2022
Yes, the failure point
nushell/src/main.rs
Line 50 in 46eec5e
IanManske commentedon Oct 19, 2022
I am getting the same panic/message on linux when running nu through my window manager (sway).
(E.g., using a key binding to run a nu script.)
By launching nu this way, I assume there is no 'controlling terminal' which is why
ENOTTYis encountered.Correct me if I'm wrong, but I believe that encountering
ENOTTYshould not mean an immediate panic.There is even a check for this, but it is never reached due to the panic.
Also, this is with nu version
0.70.0(the latest package release for arch).melMass commentedon Oct 28, 2022
To add to this, to debug tty apps in VSCode you must use
"console": "integratedTerminal"(source: microsoft/vscode-cpptools#3351 (comment)).But this seems to be ignored for Rust?:

This is my config
launch.json
rgwood commentedon Oct 29, 2022
I tried to bisect this, but went pretty far back (July 31) and still didn't find a commit where debugging was working.
The backtrace changed somewhere between df6a7b6 and 5959d13. On df6a7b6 and earlier, the debugger was panicking with an 'attempt to subtract with overflow' in reedline.
jokeyrhyme commentedon Oct 30, 2022
Is there a workaround in 0.70.0 to avoid the tcgetpgrp NOTTY panic? Is there an opposite of the --interactive flag that will bypass this check?
Kangaxx-0 commentedon Nov 23, 2022
This is a hard stop for me to contribute
nurepo without debugging code, I spent some time and still could not make it working, tried native windows which is a such awful thing :( I am also wondering if you guys are using Mac ?If someone knows how to work around this issue, that would be super helpful.
jokeyrhyme commentedon Nov 23, 2022
0.71.0 includes the ENOTTY fix: https://www.nushell.sh/blog/2022-11-08-nushell-0.71.html #7001
Kangaxx-0 commentedon Nov 23, 2022
Does it work for you? I built the dev binary against latest main, and it does not work
jokeyrhyme commentedon Nov 23, 2022
@Kangaxx-0 I ran into the ENOTTY bug via a different shortcut (wayland keybindings triggering nushell scripts directly), so it's possible that there is some other problem specific to VSCode
But yes, for my use case, 0.71.0 fixes my issues
Do you still get that ENOTTY error or is it a different error now?
And do you set
"console"as per #6788 (comment) ?Kangaxx-0 commentedon Nov 23, 2022
I've got one Linux laptop and one Azure VM, they both ended up with error
no TTY for interactive shell, I did add that config and still not working, as far as I could tell, theinteractiveboolean is set totrue, so the later fix does not really workKangaxx-0 commentedon Nov 23, 2022
VSCode + LLDB is the only way I debug Rust code, if you guys has another way to debug day to day, I'd like to learn from you :)
fdncred commentedon Nov 23, 2022
I'd love to get this fixed but unfortunately, all I get with CodeLLDB is
rgwood commentedon Dec 14, 2022
@Kangaxx-0
gdbworks. Like Stefan mentioned, you can attach it to Nu withgdb -p <nu pid>.I avoided
gdbfor a long time and this LLDB bug is forcing me to finally learn it properly 😅 , better late than never.Kangaxx-0 commentedon Dec 25, 2022
Thanks for you guys sharing, I'd figured it out but forgot to leave some step-by-step instruction in case someone like me having the same issue
I am taking my Linux devbox as example:
sudo apt intstall gdb, you could change the command if you are on different distronushell/target/devfolder./nu, you also want to find the running PID byps | where name =~ 'nu' | where status == 'Running'gdbattach <PID>break <file>:<line>alesito85 commentedon Feb 9, 2023
I'm also having issues using lldb and TTY. But it works well if I use lldb attach when I start the debug version of the built binary.
sholderbach commentedon Feb 10, 2023
@alesito85 thanks for sharing that config for reference. It certainly helps to get by with some IDE conveniences.
While skipping the startup spares those bugs there are situations where it would be helpful to be able to debug the startup directly.
alesito85 commentedon Feb 16, 2023
@sholderbach yeah I definitely agree, but better than nothing in the mean time.
I've been doing a bit more digging and I've found that if the whole following range is commented out and success set to true, the debugging will run well in VSCode on Mac and it will accept user input and return data.
https://github.com/nushell/nushell/blob/main/src/terminal.rs#L62..L92
This is obviously not ok for production, but would it be fine for debugging only/debug version?
I'm not entirely clear on the ramifications that this would bring and I'd appreciate if someone would clear it up for me.
IanManske commentedon Jul 14, 2023
@alesito85 @sholderbach The commented out lines are probably only relevant if nushell is being run from within another shell. For example, the last few lines handle job handling (
&in bash) and allows nushell to be sent to the background. I'm not sure whyENOTTYis being encountered. This means there was no controlling terminal for nushell. Maybe it's a bug with VS Code or LLDB? Anyways, I think it's fine to disable these lines during debugging.