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

[BUG] - prompt not showing due to terraform plugin #2598

Open
juanmatias opened this issue Mar 11, 2024 · 15 comments
Open

[BUG] - prompt not showing due to terraform plugin #2598

juanmatias opened this issue Mar 11, 2024 · 15 comments

Comments

@juanmatias
Copy link

Randomly prompt is not shown with zsh+ohmyzsh+powerlevel10k

What?

I'm using zsh+ohmyzsh+powerlevel10k on a Manjaro.

The problem is that from time to time shell doesn't show the prompt.
This is fixed after a couple of restarts.
Other shells start well.

Possible cause

If I remove the Terraform plugin from powerlevel10k it starts.

I'm removing it from .p10k.zsh from POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS variable.

Request for help

I am not sure how to dig into this to find the root cause. Could you guide me on how to debug this so I can find a fix?

Workaround

For now I have it deactivated.

Other info

❯ uname -a
Linux tufmanjaro 5.15.148-2-MANJARO #1 SMP PREEMPT Sat Feb 10 11:45:52 UTC 2024 x86_64 GNU/Linux

I have installed these packages:

  • extra/zsh 5.9-4
  • aur/zsh-theme-powerlevel10k-git r3918.25e5f59-1
@romkatv
Copy link
Owner

romkatv commented Mar 11, 2024

The problem is that from time to time shell doesn't show the prompt.

What does that look like?

@juanmatias
Copy link
Author

hey @romkatv thanks for answering

at those times, when I start a terminal it remains blank

if I open a different shell (bash or fish), and from there I try to run zsh it hangs

adding set -xv I don't get to much info, except the word powerlevel and terraform.

first I disabled powerlevel10k, zsh started ok (with an ugly prompt :) )

so, following a hunch, I did a search in p10k config file, found terraform loaded under POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS and I commented the line. Then zsh started fine.

@romkatv
Copy link
Owner

romkatv commented Mar 11, 2024

Can you confirm that without terraform everything works but with terraform zsh hangs on start? If you try 3 times each, does it reproduce 100% of the time?

@juanmatias
Copy link
Author

I'll try to reproduce this and collect data to do better debugging.
Can you recommend anything in particular to take into account?

@romkatv
Copy link
Owner

romkatv commented Mar 11, 2024

Nothing in particular. Just a clear cause and effect: when I do X, Y happens, 100%.

@juanmatias
Copy link
Author

juanmatias commented Mar 15, 2024

@romkatv it happened again

While zsh hangs, I still can open fish and bash.

In the .p10k.zsh file, under typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( the option terraform is enabled (i.e. it is uncommented).

I added set -xv to the .zshrc file.

From bash I try to load zsh and it hangs. The last logs are:

+_p9k_set_prompt:34> _p9k__segment_name=terraform
+_p9k_set_prompt:35> local cond='$commands[terraform]'
+_p9k_set_prompt:36> [[ -z '$commands[terraform]' || -n /home/jdelacamara/.asdf/shims/terraform ]]
+_p9k_set_prompt:37> local disabled=_POWERLEVEL9K_TERRAFORM_DISABLED_DIR_PATTERN
+_p9k_set_prompt:38> [[ /home/jdelacamara !=  ]]
+_p9k_set_prompt:39> local val=''
+_p9k_set_prompt:40> [[ -n '' ]]
+_p9k_set_prompt:43> [[ terraform == custom_* ]]
+_p9k_set_prompt:45> ((  1  ))
+_p9k_set_prompt:46> prompt_terraform
+prompt_terraform:1> local ws=''
+prompt_terraform:2> [[ -z '' ]]

CTRL+C does not work. Only a killall -9 zsh finishes the process.

Full output:
first-zsh-load.log

Then I comment the terraform line in .p10k.zsh under typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(.

This time when running zsh it works.

Full logs:
first-zsh-load-with-commented-line.log

If I uncomment the line, zsh hangs again. And if comment it again zsh works.

@romkatv
Copy link
Owner

romkatv commented Mar 16, 2024

Thanks for the extra info.

It looks like zsh hangs trying to resolve ${${TF_DATA_DIR:-.terraform}:A}/environment. Could you confirm this? To do that, run the following command:

zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'

You need to run this from the same directory in which you ran your previous tests when zsh was hanging on start.

What does the command print? Does it hang?

@juanmatias
Copy link
Author

@romkatv I've run zsh from my home dir previously.

Here it is your command in the home dir:

❯ zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'
+zsh:1> :
+zsh:1> ls -ld -- .terraform
ls: cannot access '.terraform': No such file or directory

It hangs here. But I can cancel with CTRL+C.

Btw, it makes sense not to have the .terraform dir here since it's my home dir.

@romkatv
Copy link
Owner

romkatv commented Mar 16, 2024

This is fascinating. Does the following command also hang?

zsh -fc 'cd && : ${${:-blah}:A}'

@juanmatias
Copy link
Author

Today I started the laptop and is a day in which this is working.
I activated the terraform plugin and it works.
So, I tested the previous command again and it works:

❯ zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'
+zsh:1> :
+zsh:1> ls -ld -- .terraform
ls: cannot access '.terraform': No such file or directory
+zsh:1> : /home/jdelacamara/.terraform
❯ 

It does not hang and return to the prompt.

Right now, the last command you sent also is working.

I'll do the same test when the problem shows up again.

Meanwhile, let me know if you think I can perform more tests.

Thank you!

@romkatv
Copy link
Owner

romkatv commented Mar 18, 2024

I don't think you need to perform any more tests. The previous test (#2598 (comment)) indicates a very serious issue with your machine: realpath(3) hangs when you pass it ~/.terraform.

@juanmatias
Copy link
Author

So, can I do something?
I mean, if it is not possible I won't use terraform plugin... but if there is some kind of patch that I can create/test it would be great so I can collaborate to the project.

@romkatv
Copy link
Owner

romkatv commented Mar 18, 2024

If my diagnosis is correct, your machine has very serious issues. They aren't confined to terraform. Either the OS or the filesystem is malfunctioning.

@juanmatias
Copy link
Author

@romkatv as per your diagnosis, I'm trying to find what problem I have (before go and reinstall)....

I found the point in which it breaks is in file /usr/share/zsh-theme-powerlevel10k/internal/p10k.zsh this line:

_p9k_read_word ${${TF_DATA_DIR:-.terraform}:A}/environment && ws=$_p9k__ret

under function prompt_terraform.

I tried this in the file:

    local TFDD=${TF_DATA_DIR:-.terraform}
    local TFDD2=${TFDD:A}

...and it fails anyway in the second line.

I'm trying to figure it out, but I left the comment here just in case you have an idea.

I created the .terraform dir but it fails again.

Thanks.

@romkatv
Copy link
Owner

romkatv commented May 13, 2024

I've misread #2598 (comment). Specifically, I've missed "not" in "It does not hang". Thus, my saying that you machine has a serious issue was false.

In your last command you say "breaks" and "fails". Do you mean "hangs" in both cases?

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

2 participants