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

flake8 crash on windows-latest with UnicodeEncodeError #1381

Closed
PerchunPak opened this issue Sep 8, 2021 · 10 comments · Fixed by #1382
Closed

flake8 crash on windows-latest with UnicodeEncodeError #1381

PerchunPak opened this issue Sep 8, 2021 · 10 comments · Fixed by #1382

Comments

@PerchunPak
Copy link

Please describe how you installed Flake8

I using github actions run this check

name: Run Tests

on: push

jobs:
  test:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.9
      uses: actions/setup-python@v2
      with:
        python-version: 3.9
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8
    - name: Additional info
      run: flake8 --bug-report
    - name: Lint with flake8
      run: |
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

(also checked on other version of python, same error)

And I get this tracelog

> Run `flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics`
0
Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\hostedtoolcache\windows\Python\3.9.6\x64\Scripts\flake8.exe\__main__.py", line 7, in <module>
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\main\cli.py", line 22, in main
    app.run(argv)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\main\application.py", line 363, in run
    self._run(argv)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\main\application.py", line 352, in _run
    self.report()
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\main\application.py", line 343, in report
    self.report_errors()
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\main\application.py", line 298, in report_errors
    results = self.file_checker_manager.report()
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\checker.py", line 261, in report
    results_reported += self._handle_results(filename, results)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\checker.py", line 159, in _handle_results
    reported_results_count += style_guide.handle_error(
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\style_guide.py", line 424, in handle_error
    return guide.handle_error(
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\style_guide.py", line 579, in handle_error
    self.formatter.handle(error)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\formatting\base.py", line 95, in handle
    self.write(line, source)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\formatting\base.py", line 206, in write
    self._write(line)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\site-packages\flake8\formatting\base.py", line 189, in _write
    print(output, end=self.newline)
  File "c:\hostedtoolcache\windows\python\3.9.6\x64\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 36-40: character maps to <undefined>

Please provide the exact, unmodified output of flake8 --bug-report

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.9.6",
    "system": "Windows"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.7.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.3.1"
    }
  ],
  "version": "3.9.2"
}

P.S. Using forked repository from this commit

@asottile
Copy link
Member

asottile commented Sep 8, 2021

I believe it's trying to write out your source? which may contain un-encodable characters?

@asottile
Copy link
Member

asottile commented Sep 8, 2021

I can't reproduce unfortunately. it works for me

@PerchunPak
Copy link
Author

Hmm. Try fork my repo as private and reproduce there

@asottile
Copy link
Member

asottile commented Sep 8, 2021

I have your repository cloned at the revision above:

C:\Users\Anthony\workspace\PingerBot>git rev-parse HEAD
db64725bc964213fe2eb0783f23f69ef3236c5b4

C:\Users\Anthony\workspace\PingerBot>venv\Scripts\flake8 --version
3.9.2 (mccabe: 0.6.1, pycodestyle: 2.7.0, pyflakes: 2.3.1) CPython 3.9.0 on Windows

@PerchunPak
Copy link
Author

I mean reproduce it with github actions, not localy

@asottile
Copy link
Member

asottile commented Sep 8, 2021

hmm ok it reproduces with flake8 ... | cat so it's an io-encoding issue

if you remove --show-source you can probably work around it

@asottile
Copy link
Member

asottile commented Sep 8, 2021

can you try the patch in #1382 ?

@PerchunPak
Copy link
Author

how i can use it in github actions?

@asottile
Copy link
Member

asottile commented Sep 8, 2021

@PerchunPak
Copy link
Author

yea, it working. thanks

@asottile asottile reopened this Sep 8, 2021
@asottile asottile added this to the 4.0.0 milestone Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants