Skip to content

yapf code formatting deletes file if it does not parse #61

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

Closed
achalddave opened this issue Nov 2, 2015 · 5 comments · Fixed by #165
Closed

yapf code formatting deletes file if it does not parse #61

achalddave opened this issue Nov 2, 2015 · 5 comments · Fixed by #165
Labels

Comments

@achalddave
Copy link
Contributor

If you have a file that does not parse correctly by Python, yapf returns an error, and does not print anything to stdout. codefmt reads the stdout from yapf, and replaces the vim buffer with it, which means that a file with the below contents (note the missing end quote)

print 'hello

will be emptied when codefmt is run.

@dbarnett dbarnett added the bug label Nov 2, 2015
@dbarnett
Copy link
Contributor

dbarnett commented Nov 2, 2015

Eesh, sounds like it's not checking exit code. Should be an easy fix.

dbarnett added a commit that referenced this issue Nov 7, 2015
Fixes #61: Catch yapf errors instead of overwriting file
@scottstanie
Copy link

This is still happening to me, but as a result of a strange corner case.

I installed yapf using conda, originally with Python 3.6. I switch the python version to 3.8, which I thought was supposed to reinstall all packages. However, when I run yapf from the command line, I get this error:

$ ~/miniconda3/envs/mapping/bin/yapf
-bash: /home/scott/miniconda3/envs/mapping/bin/yapf: /home/scott/miniconda3/envs/mapping/bin/python3.6: bad interpreter: No such file or directory

It's definitely this same issue, as when I change the line autocmd FileType python AutoFormatBuffer yapf in my .vimrc to autocmd FileType python AutoFormatBuffer autopep8, the deleting bug goes away.

Also, I was able to solve this by uninstalling yapf and reinstalling, so that the bad interpreter error went away, but it seemed worth noting here.

@dbarnett
Copy link
Contributor

dbarnett commented Nov 6, 2020

I suspect the remaining issue is that it's returning a non-zero exit code besides 1. The fix only checked if the exit code was 1 (v:shell_error == 1), but any non-zero exit code indicates the command failed.

@agriffis
Copy link
Contributor

agriffis commented Nov 8, 2020

Bad interpreter is exit code 126

@dbarnett
Copy link
Contributor

Yup, that's what I was seeing. I'm going to go ahead and loosen that v:shell_error == 1 to any non-zero exit code and mark this fixed again. Then I can check if that gives us any interesting new results for #164.

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

Successfully merging a pull request may close this issue.

4 participants