powerline-shell icon indicating copy to clipboard operation
powerline-shell copied to clipboard

Strange Segment error in certain directories

Open jrjhealey opened this issue 7 years ago • 6 comments

I've been using Powerline for a little while now but just today I noticed that the PS1 freaks out in certain directories.

Specifically I get the following:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/wms_joe/bin/miniconda2/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 68, in run
    self.stats, self.branch = build_stats()
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 55, in build_stats
    branch_info = parse_git_branch_info(status)
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 7, in parse_git_branch_info
    info = re.search('^## (?P<local>\S+?)''(\.{3}(?P<remote>\S+?)( \[(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?\])?)?$', status[0])
IndexError: list index out of range

Traceback (most recent call last):
  File "/home/wms_joe/bin/miniconda2/bin/powerline-shell", line 9, in <module>
    load_entry_point('powerline-shell==0.5.4', 'console_scripts', 'powerline-shell')()
  File "build/bdist.linux-x86_64/egg/powerline_shell/__init__.py", line 224, in main
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 72, in add_to_powerline
AttributeError: 'Segment' object has no attribute 'stats'

And this happens inside my git repository that resides here:

https://github.com/jrjhealey/MultiGeneBlastParser

However, if I clone that repo on my mac locally, everything is fine. If I cd in to that directory on a Ubuntu server however I get the above error. cd-ing back in to another directory restores the powerline. Other git repos on the same Ubuntu box work without issue however.

I've deleted the repo and recloned it on the Ubuntu machine and the same problem appears.

Both systems are using Bash as the shell.

Any ideas?

jrjhealey avatar May 31 '18 07:05 jrjhealey

I've discovered that the segment errors will disappear so long as the directory contains a .gitignore file, even if it is empty; touch .gitignore inside the repo folder is sufficient.

jrjhealey avatar Aug 22 '18 16:08 jrjhealey

Hello, please reopen the issue I have the .gitignore file but the error persist:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 68, in run
    self.stats, self.branch = build_stats()
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 55, in build_stats
    branch_info = parse_git_branch_info(status)
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 7, in parse_git_branch_info
    info = re.search('^## (?P<local>\S+?)''(\.{3}(?P<remote>\S+?)( \[(ahead (?P<ahead>\d+)(, )?)?(behind (?P<behind>\d+))?\])?)?$', status[0])
IndexError: list index out of range

Traceback (most recent call last):
  File "/home/santiago.maturana/.local/bin/powerline-shell", line 11, in <module>
    load_entry_point('powerline-shell==0.7.0', 'console_scripts', 'powerline-shell')()
  File "build/bdist.linux-x86_64/egg/powerline_shell/__init__.py", line 240, in main
  File "build/bdist.linux-x86_64/egg/powerline_shell/segments/git.py", line 72, in add_to_powerline
AttributeError: 'Segment' object has no attribute 'stats'

raistlin2912 avatar Mar 20 '19 09:03 raistlin2912

When git status shows no changes and no untracked there is the bug, but when I have any change bug gone. And when shows git segment insted the branch name shows strange version number mixed with last commit hash.

raistlin2912 avatar Mar 20 '19 09:03 raistlin2912

Thanks for adding to this, I’ve discovered the same thing. Some logic for handling just the situation when a repo is unmodified should be all that’s needed.

jrjhealey avatar Mar 20 '19 20:03 jrjhealey

This started happening today for me, too. But with svn instead of git:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/dist-packages/powerline_shell/segments/svn.py", line 54, in run
    self.stats, self.revision = build_stats()
  File "/usr/local/lib/python3.6/dist-packages/powerline_shell/segments/svn.py", line 48, in build_stats
    revision = _get_svn_revision()
  File "/usr/local/lib/python3.6/dist-packages/powerline_shell/segments/svn.py", line 14, in _get_svn_revision
    return revision
UnboundLocalError: local variable 'revision' referenced before assignment

Traceback (most recent call last):
  File "/usr/local/bin/powerline-shell", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/powerline_shell/__init__.py", line 240, in main
    segment.add_to_powerline()
  File "/usr/local/lib/python3.6/dist-packages/powerline_shell/segments/svn.py", line 58, in add_to_powerline
    if not self.stats:
AttributeError: 'Segment' object has no attribute 'stats'

So I removed the "svn", entry from my config.json, and then issue #343 started happening. After adding @eightnoteight's fix export PYTHONIOENCODING='utf8', the powerline works again.

But even with the export, adding "svn" to the config breaks powerline, so please don't close the issue yet.

Edit: I forgot to add, this appears to be happening regardless of folder, and since it's happening with svn instead of git for me, it's regardless of .gitignore file.

rklasen avatar Mar 25 '19 17:03 rklasen

I'm still seeing this issue.

@b-ryan: Here's a pretty harmless change which I think (but haven't verified) should fix the issue: https://github.com/b-ryan/powerline-shell/issues/408

Olshansk avatar Feb 26 '20 18:02 Olshansk