Skip to content
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

VS Code will tell the terminal process terminated with an error code if the last command failed when exiting the terminal #33200

Closed
sylveon opened this issue Aug 27, 2017 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) help wanted Issues identified as good community contribution opportunities terminal General terminal issues that don't fall under another label
Milestone

Comments

@sylveon
Copy link
Contributor

sylveon commented Aug 27, 2017

  • VSCode Version: 1.15.1
  • OS Version: N/A (Arch Linux)

Steps to Reproduce:

  1. Open a bash integrated terminal
  2. Type the following commands:
false
exit

Expected behavior:
Shell exits without any error.

Actual behavior:
image

Reproduces without extensions: Yes

@vscodebot vscodebot bot added the terminal General terminal issues that don't fall under another label label Aug 27, 2017
@sylveon sylveon changed the title VS Code will tell the terminal process terminated with an error code if the last command failed VS Code will tell the terminal process terminated with an error code if the last command failed when exiting the terminal Aug 27, 2017
@Tyriar
Copy link
Member

Tyriar commented Aug 27, 2017

We print the exit code when it's non-zero and some shells seem to exit with a code of 1. I'm not sure why but it also happens on Mac but not for me with my setup on Ubuntu. @sylveon any ideas why your shell returns 1 when running exit?

@Tyriar Tyriar added the info-needed Issue requires more information from poster label Aug 27, 2017
@sylveon
Copy link
Contributor Author

sylveon commented Aug 27, 2017

It returns the exit code of the last command.

For example, if I run (as non-root)

ls /root
exit

It's gonna say it terminated with code 2, which according to ls --help, means
2 if serious trouble (e.g., cannot access command-line argument).

Retaking the false example, that's because false returned 1.

If the last command succeeds, it's not complaining, since bash is gonna exit with code 0, for example this works fine

ls ~
exit

Here is my .bashrc, in case it might help:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

# Huge prompt
PS1="\`LAST_COMMAND=\$?; "                                                                              # Save last command return value for line 3 of PS1
PS1+="IFS=';' read -sdR -p $'\E[6n' ROW COL; if [ \${COL#*[} -ne 1 ]; then echo -n $'\n'; fi; "         # Print a new line if the last command did not have one
PS1+="if [ \$LAST_COMMAND -eq 0 ]; then echo \[\e[1\;33m\]^_^; else echo \[\e[1\;31m\]O_O; fi\`"        # Print a different smiley face depending on last command success
PS1+="\[\e[0m\]["                                                                                       # Reset colors and opening brace
PS1+="`if [ $EUID -eq 0 ]; then echo $'\e[31m'; fi`"                                                    # Print username red if running as root
PS1+="`getent passwd $LOGNAME | cut -d: -f5 | cut -d, -f1`"                                             # Print pretty username
PS1+="\[\e[0m\]@"                                                                                       # Reset colors and at symbol
PS1+="`awk -F= '/PRETTY/ {gsub(/"/,"");print $2}' /etc/machine-info` "                                  # Print pretty machine name
PS1+="\[\e[1;36m\]\w\[\e[0m\]]\\$ "                                                                     # The rest of the fucking owl

# Aliases, features and environment variables
alias su='sudo su'                                                                                      # Make su work when root login is disabled
if [[ $EUID -ne 0 ]]; then alias pacman='pacaur'; fi                                                    # Pacaur won't run as root, so set alias only for non-root
alias ls='ls --color -A'                                                                                # Colors and hidden files by default in ls
alias grep='grep --color'                                                                               # Colors in grep
alias shutdown='sudo shutdown'                                                                          # Handy alias
alias poweroff='sudo shutdown -h now'                                                                   # ^
alias reboot='sudo shutdown -r now'                                                                     # ^
shopt -s autocd                                                                                         # Automatically CD to a folder if we enter it directly to the prompt
source /usr/share/doc/pkgfile/command-not-found.bash                                                    # Show if a missing command can be found in a package
export PKGFILE_PROMPT_INSTALL_MISSING=1                                                                 # Prompt to install said package
export HASTE_SERVER=https://haste.charlesmilette.net                                                    # Custom server for hastebin uploader script
export PROMPT_DIRTRIM=4                                                                                 # Trim directory in prompt if too long
shopt -s cdspell                                                                                        # Fix those fucking typos
shopt -s dirspell                                                                                       # ^
eval "$(thefuck --alias)"                                                                               # FUCK
eval "$(hub alias -s)" 

@rianadon
Copy link
Contributor

WSL bash also behaves the same way. Likewise with cmd.exe on Windows.

For example, typing the following in a cmd.exe terminal reproduces the error:

> bash
$ false
$ exit
> exit

@Tyriar
Copy link
Member

Tyriar commented Aug 27, 2017

If exit does indeed make the shell return non-zero there isn't much we can do until we know what command is being run #20676

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Aug 27, 2017
@Tyriar Tyriar added this to the Backlog milestone Aug 27, 2017
@josecrmrz
Copy link

I also noticed this on both Windows 10 and Ubuntu. What I did was try to exit but I miss typed it but I get the error code 127 instead of 1 on both operating systems

> ext
bash: ext: command not found
> exit

@danieltorrecillas
Copy link

I'm able to reproduce the use case by @josecrmrz above. That is,

$ ext
bash: ext: command not found
$ exit

The terminal closes and I get the banner at the top showing:

The terminal process terminated with exit code: 127

Code 1.18.1
macOS 10.13.1

@levrik
Copy link

levrik commented Dec 15, 2017

Facing this issue too on macOS with zsh.
Attached a GIF for better understanding of this issue.

kapture 2017-12-15 at 10 31 47

@Tyriar Tyriar added the help wanted Issues identified as good community contribution opportunities label Dec 15, 2017
@Tyriar
Copy link
Member

Tyriar commented Dec 26, 2017

Closing in favor of #40503

@Tyriar Tyriar closed this as completed Dec 26, 2017
@Tyriar Tyriar added the *duplicate Issue identified as a duplicate of another issue(s) label Dec 26, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) help wanted Issues identified as good community contribution opportunities terminal General terminal issues that don't fall under another label
Projects
None yet
Development

No branches or pull requests

7 participants