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

Strange Segment error in certain directories #408

Open
jrjhealey opened this issue May 31, 2018 · 6 comments
Open

Strange Segment error in certain directories #408

jrjhealey opened this issue May 31, 2018 · 6 comments

Comments

@jrjhealey
Copy link

jrjhealey commented May 31, 2018

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
Copy link
Author

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.

@raistlin2912
Copy link

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
Copy link

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.

@jrjhealey
Copy link
Author

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.

@rklasen
Copy link

rklasen commented Mar 25, 2019

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.

strnk added a commit to strnk/powerline-shell that referenced this issue Aug 28, 2019
Olshansk added a commit to Olshansk/powerline-shell that referenced this issue Feb 26, 2020
Initialize stats and branch of the Segment class to None.

This should hopefully fix the issue outline in b-ryan#408:

```
AttributeError: 'Segment' object has no attribute 'stats'
```
@Olshansk
Copy link

Olshansk commented Feb 26, 2020

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: #408

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

4 participants