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

Returning code always 0 in VS Code terminal #595

Open
hgsantana opened this issue Aug 28, 2024 · 5 comments
Open

Returning code always 0 in VS Code terminal #595

hgsantana opened this issue Aug 28, 2024 · 5 comments

Comments

@hgsantana
Copy link

hgsantana commented Aug 28, 2024

I've been trying to customize a new theme for my needs, and I was trying to use robbyrussell theme as the base for it. When I tried the false command using this theme it didn't apply the brown color to the arrow as it was supposed to do.

So I tried to debug it and placed an "echo $?" just inside the function that generates de prompt:

function _omb_theme_PROMPT_COMMAND() {
  echo "return code $?" # line I added
  if [[ "$?" == 0 ]]; then
    local arrow_color="${_omb_prompt_bold_green}"
  else
    local arrow_color="${_omb_prompt_bold_brown}"
  fi
...

Even typing false on prompt, the return code is always 0:

➜  ~ false
return code 0
➜  ~ true
return code 0

The if statement would always be 0 after I added the new line, since echo returns 0 on success. Nevertheless, the print of $? is always 0 inside the echo command. Something before this function is returning 0 and is not the command executed on prompt.

@akinomyoga
Copy link
Contributor

It works as expected in my environment (the printed code changes depending on the exit status of the previous command). Do you load other frameworks? What is the result of declare -p PROMPT_COMMAND?

$ declare -p PROMPT_COMMAND

@akinomyoga
Copy link
Contributor

akinomyoga commented Aug 28, 2024

@Gaurav9812 Your account is likely to be hijacked. That link is reported as a virus.

Currently, a massive number of messages of the same malicious content seem to be posted by different users (which includes various types of inactive users seemingly owned by real people):

@hgsantana
Copy link
Author

The result of $ declare -p PROMPT_COMMAND is:

declare -a PROMPT_COMMAND=([0]="__vsc_prompt_cmd_original")

I've just realized the problem occurs inside VS Code terminal.

@hgsantana hgsantana changed the title Returning code always 0 Returning code always 0 in VS Code terminal Aug 28, 2024
@akinomyoga
Copy link
Contributor

akinomyoga commented Aug 28, 2024

The upstream integration code is clearly broken.

__vsc_prompt_cmd_original() {
	__vsc_status="$?"
	__vsc_restore_exit_code "${__vsc_status}"
	# Evaluate the original PROMPT_COMMAND similarly to how bash would normally
	# See https://unix.stackexchange.com/a/672843 for technique
	builtin local cmd
	for cmd in "${__vsc_original_prompt_command[@]}"; do
		eval "${cmd:-}"
	done
	__vsc_precmd
}

While it saves the exit status in the variable __vsc_status (line 330) and tries to restore it (line 331), it's applied to builtin local cmd (line 334). This doesn't make any sense. The restoration of the exit status should be applied to line 336. Git Blame reveals that microsoft/vscode#221772 (edit: sorry, this was not the culprit) microsoft/vscode#208364 broke this by inserting local cmd in a wrong line.

Edit: The issue is also reported in the upstream:

@akinomyoga
Copy link
Contributor

The fix in VSCode seems to have been released in 1.93.0. @hgsantana Could you check if the problem is fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@akinomyoga @hgsantana and others